Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions queue_job/jobrunner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
import datetime
import logging
import os
import select
import selectors
import threading
import time
from contextlib import closing, contextmanager
Expand All @@ -162,6 +162,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
Expand Down Expand Up @@ -485,10 +487,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")
Expand Down