Skip to content

Commit 2294843

Browse files
committed
Fix compatibility for Python 3.7 and 3.8 in WorkerClass
- Retained the original logic of using get_event_loop() for obtaining the event loop. - Added conditional handling for setting up the stopping event based on Python version. - Ensured that the code remains compatible with existing functionality while supporting older Python versions.
1 parent b4afb97 commit 2294843

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/tsignal/contrib/patterns/worker/decorators.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import threading
33
import logging
44
import time
5+
import sys
56

67
logger = logging.getLogger(__name__)
78

@@ -16,12 +17,15 @@ class WorkerClass(cls):
1617
def __init__(self):
1718
self._worker_loop = None
1819
self._worker_thread = None
19-
self._stopping = asyncio.Event()
2020
self._task_queue = asyncio.Queue()
2121
# Setting up thread/loop for compatibility with t_with_signals
2222
self._thread = threading.current_thread()
2323
try:
2424
self._loop = asyncio.get_event_loop()
25+
if sys.version_info < (3, 9):
26+
self._stopping = asyncio.Event(loop=self._loop)
27+
else:
28+
self._stopping = asyncio.Event()
2529
except RuntimeError:
2630
self._loop = asyncio.new_event_loop()
2731
asyncio.set_event_loop(self._loop)

0 commit comments

Comments
 (0)