-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle gateway timeout #80
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #80 +/- ##
==========================================
- Coverage 33.13% 32.64% -0.50%
==========================================
Files 13 13
Lines 845 873 +28
==========================================
+ Hits 280 285 +5
- Misses 565 588 +23 ☔ View full report in Codecov by Sentry. |
I pulled this down to test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not looked at the code closely: the networking/watchdog stuff is new to me, but the event handling seems fine.
However, what I see when using this PR is that if I connect to OMERO and then close napari, napari closes are normal, but the process stays alive and I need to Control-C (or kill from task manager).
I suspect this is due to the thread worker and the thread/connection not being closed properly.
Edit:
If I disconnect in the plugin, the hung state still occurs after quitting napari.
@will-moore maybe you have some feedback on the Gateway side of things in this PR? |
Thanks for testing! I think it should be relatively easy to kill the thread upon clicking the disconnect button. I would have to look a bit on how to connect the napari-is-destroyed-event something that would terminate the thread. |
You could also try using a daemon thread (set daemon=True when you create it) |
Reading up further, as I'm rather threading naive, it looks like FunctionWorkers don't have a way to stop something until it finishes, and you have a Using a |
that's correct. there's no real way in python to "interact" with a running function. so it's best to use a generator or anything that can yield periodically to ask whether it should stop |
Ok, I made some changes to address this:
|
@jo-mueller When I launch from jupyter I think I see the extra process and indeed it's not shutdown when napari closes. |
Fixes #71
This pull request introduces a connection watchdog to the
QGateWay
class to monitor the connection status and handle disconnections more gracefully. Basically, thesocket
module is used to check whether a connection togateway._host
andgateway._port
can be established. If it can't, thedisconnect
signal is emitted, triggering the built-in teardown of the treeview and displaying an error message.Connection monitoring:
src/napari_omero/widgets/gateway.py
: Introduced a_connection_watchdog
function to periodically check the connection status and emit a disconnect signal if the connection times out. Added a_check_connection
helper function to attempt socket connections.src/napari_omero/widgets/gateway.py
: Added a_connection_watchdog_timout
attribute to set the watchdog timeout interval.Session handling:
src/napari_omero/widgets/gateway.py
: Updated the_on_new_session
method to start the connection watchdog in a separate thread usingcreate_worker
fromnapari.qt.threading
.Disconnection handling:
src/napari_omero/widgets/main.py
: Connected thedisconnected
signal from the gateway to the_on_disconnect
handler to manage UI changes on disconnection.Tested
I tested the approach by connecting to the OMERO instance I have access to and then cutting the VPN tunnel. It takes a few seconds for the plugin to fall back to the login view, but it does it :) That behavior can probably be tuned by setting better timeout values.