diff options
author | Carey Metcalfe <carey@cmetcalfe.ca> | 2018-01-06 16:52:17 -0500 |
---|---|---|
committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2018-01-06 23:52:17 +0200 |
commit | 5b402ec0e8643bcad9ff37d3dfd3a849c7b1066f (patch) | |
tree | 83b9f829817d8304bb7dbe95663c115f9b62138c | |
parent | 01dcea45ade6962f9f2aee8a552f7be39dc40af3 (diff) | |
download | apscheduler-5b402ec0e8643bcad9ff37d3dfd3a849c7b1066f.tar.gz |
Prevent deadlocks in scheduler shutdown (#268)
By splitting up the executor lock and jobstore lock, this allows jobs
that are shutting down to query their state from the database (requiring
`self._jobstore_lock`) without causing a deadlock.
Since setting `self.state` above prevents new jobs from being added to the
executors as they shut down, breaking up these locks won't allow new
jobs to run while the scheduler is shutting down.
-rw-r--r-- | apscheduler/schedulers/base.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/apscheduler/schedulers/base.py b/apscheduler/schedulers/base.py index d777ed9..f7c65f7 100644 --- a/apscheduler/schedulers/base.py +++ b/apscheduler/schedulers/base.py @@ -178,12 +178,13 @@ class BaseScheduler(six.with_metaclass(ABCMeta)): self.state = STATE_STOPPED - with self._jobstores_lock, self._executors_lock: - # Shut down all executors + # Shut down all executors + with self._executors_lock: for executor in six.itervalues(self._executors): executor.shutdown(wait) - # Shut down all job stores + # Shut down all job stores + with self._jobstores_lock: for jobstore in six.itervalues(self._jobstores): jobstore.shutdown() |