Commit 7656e69d authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Merge branch 'mnt/organise' into 'master'

Update message handler argument order

See merge request !3
parents 6066e38e eac1eb12
......@@ -11,7 +11,7 @@ import fsl.wrappers as wrappers
import fsl.gui.server as fslserver
async def set_input(sid, sio, msg):
async def set_input(sio, sid, 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'``.
......@@ -22,7 +22,7 @@ async def set_input(sid, sio, msg):
await sio.emit('output', {'filename' : outfile}, room=sid)
async def run_bet(sid, sio, msg):
async def run_bet(sio, sid, 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.
......
#!/usr/bin/env python
#
import sys
import functools as ft
import socketio
import textwrap as tw
def main():
......@@ -12,18 +11,21 @@ def main():
server_url = sys.argv[1]
infile = sys.argv[2]
sio = socketio.Client(logger=True,
engineio_logger=True)
sio = socketio.Client()
def on_connect():
print('Connected - sending input file')
sio.emit('input', {'filename' : infile})
def on_output(data):
def on_output_image(data):
outfile = data['filename']
print(f'Received output event {data}')
sio.emit('run', {'input' : infile, 'output' : outfile})
def on_output(data, msgtype):
print(f'Received {msgtype} event:')
print(' ', data['data'])
def on_command(data):
print('Received command event:')
print(' ', data['command'])
......@@ -32,15 +34,24 @@ def main():
print('Received finished event')
print(' exit code: ', data['exitcode'])
print(' total time:', data['totaltime'])
sio.emit('shutdown', {})
# don't disconnect until we're sure that the
# server has received the shutdown event
sio.emit('shutdown', {}, callback=on_shutdown)
def on_shutdown():
sio.disconnect()
on_stdout = ft.partial(on_output, msgtype='stdout')
on_stderr = ft.partial(on_output, msgtype='stderr')
sio.on('connect', on_connect)
sio.on('output', on_output)
sio.on('output', on_output_image)
sio.on('stdout', on_stdout)
sio.on('stderr', on_stderr)
sio.on('command', on_command)
sio.on('success', on_finished)
sio.on('error', on_finished)
sio.on('error', on_finished)
sio.connect(server_url)
sio.wait()
......
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