Commit 5f8ec497 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Port over to async execution.

parent af67a347
......@@ -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__':
......
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