Skip to content

Commit

Permalink
Prevent deadlocks in scheduler shutdown (#268)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pR0Ps authored and agronholm committed Jan 6, 2018
1 parent 01dcea4 commit 5b402ec
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apscheduler/schedulers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,13 @@ def shutdown(self, wait=True):

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()

Expand Down

0 comments on commit 5b402ec

Please sign in to comment.