Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
gui
fsl-gui-bet
Commits
eac1eb12
Commit
eac1eb12
authored
Mar 24, 2021
by
Paul McCarthy
🚵
Browse files
TEST: Test client listens for stdout/err events, shuts down cleanly
parent
c2130cfb
Changes
1
Hide whitespace changes
Inline
Side-by-side
python/fsl/gui/bet/tests/test_bet.py
View file @
eac1eb12
#!/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
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment