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 fsl.utils.run as run
import fsl.data.image 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:`fsl.wrappers.bet` function.
"""
# TODO make this non blocking
cmd = wrappers.bet(**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
else:
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.connect(server_url)
sio = socketio.Client(logger=True,
engineio_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):
sio.disconnect()
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.disconnect()
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)
sio.connect(server_url)
sio.wait()
if __name__ == '__main__':
sys.exit(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