From 0b02d77ef70bdc16a7f2ed65d9b6bbb5b15c17a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 13 Jan 2021 13:37:06 +0200 Subject: Get the asyncio event loop in start() and not in __init()__ Fixes #484. --- apscheduler/schedulers/asyncio.py | 8 +++++++- docs/versionhistory.rst | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apscheduler/schedulers/asyncio.py b/apscheduler/schedulers/asyncio.py index 289ef13..9ab7221 100644 --- a/apscheduler/schedulers/asyncio.py +++ b/apscheduler/schedulers/asyncio.py @@ -38,13 +38,19 @@ class AsyncIOScheduler(BaseScheduler): _eventloop = None _timeout = None + def start(self, paused=False): + if not self._eventloop: + self._eventloop = asyncio.get_event_loop() + + super().start(paused) + @run_in_event_loop def shutdown(self, wait=True): super(AsyncIOScheduler, self).shutdown(wait) self._stop_timer() def _configure(self, config): - self._eventloop = maybe_ref(config.pop('event_loop', None)) or asyncio.get_event_loop() + self._eventloop = maybe_ref(config.pop('event_loop', None)) super(AsyncIOScheduler, self)._configure(config) def _start_timer(self, wait_seconds): diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index 578f496..772b520 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -12,6 +12,9 @@ APScheduler, see the :doc:`migration section `. * Pinned ``tzlocal`` to a version compatible with pytz * Ensured that jitter is always non-negative to prevent triggers from firing more often than intended +* Changed ``AsyncIOScheduler`` to obtain the event loop in ``start()`` instead of ``__init__()``, + to prevent situations where the scheduler won't run because it's using a different event loop + than then one currently running * Made it possible to create weak references to ``Job`` instances * Fixed Zookeeper job store using backslashes instead of forward slashes for paths on Windows (PR by Laurel-rao) -- cgit v1.2.1