diff options
| author | 2019-09-17 13:39:23 +0100 | |
|---|---|---|
| committer | 2019-09-17 13:39:23 +0100 | |
| commit | d454f9b732eb26576782e5f3e27c69197490a12f (patch) | |
| tree | fcb5aed19d72aa53266939873c441c29212d3b13 | |
| parent | 'srt' -> 'str' (diff) | |
| signature | ||
use Queue.get() with timeout, not Process.join() for timeout
this was because the threads spawned by multiprocessing.Queue seemed to be
making Process.join() believe the subprocess had not exited.
| -rw-r--r-- | src/utils/__init__.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 2177bbf1..ce20bdff 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,5 +1,5 @@ -import contextlib, datetime, decimal, enum, io, ipaddress, re, signal -import threading, typing +import contextlib, datetime, decimal, enum, io, ipaddress, multiprocessing +import queue, re, signal, threading, typing from src.utils import cli, consts, irc, http, parse, security class Direction(enum.Enum): @@ -390,18 +390,18 @@ def deadline_process(func: typing.Callable[[], None], seconds: int=10): try: q.put([True, func()]) except Exception as e: - print(e) q.put([False, e]) + q.close() p = multiprocessing.Process(target=_wrap, args=(func, q)) p.start() - p.join(seconds) - if p.is_alive(): - p.terminate() + try: + success, out = q.get(block=True, timeout=seconds) + except queue.Empty: + p.kill() _raise_deadline() - success, out = q.get(block=False) if success: return out else: |
