Skip to content

Commit

Permalink
Merge pull request #24 from DavidStirling/keep-alive
Browse files Browse the repository at this point in the history
Use native omero-py keepalive system
  • Loading branch information
sbesson authored Dec 11, 2024
2 parents b52085b + f9182d0 commit 0ad6903
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 37 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ reconnecting). This can be disabled as follows
omero2pandas.connect_to_omero(keep_alive=False)
```

N.b. omero2pandas uses a different system from the native OMERO API's
`client.enableKeepAlive` function, using both is unnecessary.

### Querying tables

You can also supply [PyTables condition syntax](https://www.pytables.org/usersguide/condition_syntax.html) to the `read_table` and `download_table` functions.
Expand Down
34 changes: 1 addition & 33 deletions omero2pandas/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
import getpass
import importlib.util
import logging
import threading
import time
import weakref

import Ice
import omero
from omero.gateway import BlitzGateway

LOGGER = logging.getLogger(__name__)
ACTIVE_CONNECTORS = weakref.WeakSet()
KEEPALIVE_THREAD = None


class OMEROConnection:
Expand Down Expand Up @@ -150,9 +146,7 @@ def connect(self, interactive=True, keep_alive=True):
"Not enough details to create a server connection.")
print(f"Connected to {self.server}")
if keep_alive:
# Use o2p keep alive instead of omero-py
self.client.stopKeepAlive()
start_keep_alive()
self.client.enableKeepAlive(60)
return True

def connect_widget(self):
Expand Down Expand Up @@ -280,15 +274,6 @@ def get_client(self):
LOGGER.warning("Client connection not initialised")
return self.client

def keep_alive(self):
if self.client is not None and self.session is not None:
try:
self.session.keepAlive(None)
except Ice.CommunicatorDestroyedException:
self.session = None # Was shut down
except Exception as e:
LOGGER.warning(f"Failed to keep alive: {e}")


def detect_jupyter():
# Determine whether we're running in a Jupyter Notebook.
Expand All @@ -314,21 +299,4 @@ def cleanup_sessions():
connector.shutdown()


def keep_sessions_alive():
while ACTIVE_CONNECTORS:
time.sleep(60)
for connector in ACTIVE_CONNECTORS:
connector.keep_alive()
connector = None # Don't keep a reference (would prevent shutdown!)


def start_keep_alive():
global KEEPALIVE_THREAD
if KEEPALIVE_THREAD is None or not KEEPALIVE_THREAD.is_alive():
KEEPALIVE_THREAD = threading.Thread(target=keep_sessions_alive,
name="omero2pandas_keepalive",
daemon=True)
KEEPALIVE_THREAD.start()


atexit.register(cleanup_sessions)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def read(fname):
include_package_data=True,
platforms='any',
install_requires=[
'omero-py',
'omero-py>=5.19.5',
'pandas',
'tqdm',
],
Expand Down

0 comments on commit 0ad6903

Please sign in to comment.