Open barrettMCW opened 3 weeks ago
Hi, thanks for the report. There was recently a lot of discussion on BlitzGateway connection behaviour and some tweaks in https://github.com/ome/omero-py/pull/400, so it would be good to confirm whether this issue is affected by that?
And also check that your proposed changes doesn't break the behaviour e.g. with the tests at https://github.com/ome/omero-py/pull/400#pullrequestreview-1996245019
Please feel free to open a PR with your proposed change and then we can continue the discussion there (since it will be tested by ci jobs etc). cc @sbesson @jburel
The exception looks a little different now, but sadly still failing to reconnect:
DEBUG:omero.gateway:Connect attempt, sUuid=None, group=None, self.sUuid=None
DEBUG:omero.gateway:Ooops. no self._c
INFO:root:Refresh operation completed.
INFO:omero.gateway:closed connection (uuid=None)
Exception in thread Thread-6 (compile_response):
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/home/coder/.local/lib/python3.10/site-packages/ipykernel/ipkernel.py", line 766, in run_closure
_threading_Thread_run(self)
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/tmp/ipykernel_3518/4272059447.py", line 41, in compile_response
Exception: Connection to OMERO server failed.
I'll get working on a PR
Thanks for the scenario @barrettMCW. Having reviewed the current implementation, probably the outstanding question is whether a BlitzGateway
object is expected to reconnect at all after close
has been invoked on it (either directly or via a context manager) or whether it should be treated as a resource.
Assuming the latter is the expectation, the BlitzGateway.clone()
API might offer a possible solution as it allows to instantiate a new object and preserve its properties. In other terms, the following code should work:
from omero.gateway import BlitzGateway
with BlitzGateway(host=host,username=username, passwd=passwd) as conn:
conn.connect()
# do stuff
new_conn = conn.clone()
conn.connect() # should return False
new_conn.connect() # should return True
Thanks for reviewing this @sbesson! The cloning method fixes my issues. From a pure semantic view, it makes sense to me that a gateway would open and close multiple times. But requiring a clone seems like a perfectly valid mechanism. I think if we go with the clone method we should add an example to the omero-py docs. I'll put it on my board but I probably won't get to it today. Up to y'all, either works good for me. Thanks again!
When I close the BlitzGateway then reopen it, it fails to connect, I think it's trying to reuse the client object which is attached to a closed session. I fixed it by doing:
This is called in a thread, so there might be some extra weirdness involved in causing this bug. Would there be any issues with adding the conn._resetOmeroClient method in conn.close? I can provide the full code I'm using to cause this bug if you want to attempt to replicate this, it's a relatively small class.