diff --git a/queue_job/jobrunner/runner.py b/queue_job/jobrunner/runner.py index 8dbe39d97c..6e7e08f2c8 100644 --- a/queue_job/jobrunner/runner.py +++ b/queue_job/jobrunner/runner.py @@ -136,7 +136,7 @@ import datetime import logging import os -import select +import selectors import threading import time from contextlib import closing, contextmanager @@ -156,6 +156,8 @@ _logger = logging.getLogger(__name__) +select = selectors.DefaultSelector + # Unfortunately, it is not possible to extend the Odoo # server command line arguments, so we resort to environment variables @@ -479,10 +481,16 @@ def wait_notification(self): # probably a bug _logger.debug("select() timeout: %.2f sec", timeout) if timeout > 0: - conns, _, _ = select.select(conns, [], [], timeout) if conns and not self._stop: - for conn in conns: - conn.poll() + with select() as sel: + for conn in conns: + sel.register(conn, selectors.EVENT_READ) + events = sel.select(timeout=timeout) + for key, _mask in events: + if key.fileobj == self._stop_pipe[0]: + # stop-pipe is not a conn so doesn't need poll() + continue + key.fileobj.poll() def stop(self): _logger.info("graceful stop requested")