Commit 6066e38e authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Merge branch 'mnt/organise' into 'master'

Change to asyncio-based execution

See merge request !2
parents af67a347 db1204c7
......@@ -5,32 +5,31 @@
import sys
import as run
import as fslimage
import fsl.wrappers as wrappers
import fsl.gui.server as common
import fsl.gui.server as fslserver
def set_input(sio, msg):
async def set_input(sid, sio, msg):
"""This handler is called when a message of type ``'input'`` is received.
When the user selects an input file, a default output file name is
generated and emitted via a message of type ``'output'``.
infile = msg['filename']
outfile = fslimage.removeExt(infile) + '_brain'
sio.emit('output', {'filename' : outfile})
await sio.emit('output', {'filename' : outfile}, room=sid)
def run_bet(sio, msg):
async def run_bet(sid, sio, msg):
"""This handler is called when a message of type ``'run'`` is received.
It expects to be passed all of the parameters required to run BET via the
:func:`` function.
# TODO make this non blocking
cmd =**msg, v=True, cmdonly=True)
common.run_command(sio, cmd)
await fslserver.run_command(sid, sio, cmd)
def main(argv=None):
......@@ -40,13 +39,17 @@ def main(argv=None):
if argv is None:
argv = sys.argv[1:]
port = int(argv[0])
if len(argv) == 0:
port = None
port = int(argv[0])
handlers = {
'input' : set_input,
'run' : run_bet,
common.start_server(port, handlers)
fslserver.start_server(port=port, handlers=handlers)
if __name__ == '__main__':
......@@ -7,17 +7,16 @@ import socketio
import textwrap as tw
def main():
server_url = sys.argv[1]
infile = sys.argv[2]
sio = socketio.Client()
sio = socketio.Client(logger=True,
def on_connect():
print(f'Connected - sending input file')
print('Connected - sending input file')
sio.emit('input', {'filename' : infile})
def on_output(data):
......@@ -30,23 +29,21 @@ def main():
print(' ', data['command'])
def on_finished(data):
print('Received finished event')
print(' code: ', data['exitcode'])
print(' stdout:')
print(tw.indent(data['stdout'], ' '))
print(' stderr:')
print(tw.indent(data['stderr'], ' '))
print(' exit code: ', data['exitcode'])
print(' total time:', data['totaltime'])
sio.emit('shutdown', {})
sio.on('connect', on_connect)
sio.on('output', on_output)
sio.on('command', on_command)
sio.on('finished', on_finished)
sio.on('success', on_finished)
sio.on('error', on_finished)
if __name__ == '__main__':
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment