Skip to content

Commit

Permalink
Raise RuntimeError if starting the scheduler under uWSGI without threads
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Aug 10, 2018
1 parent d21d02d commit ee7fbd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions apscheduler/schedulers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ def start(self, paused=False):
:param bool paused: if ``True``, don't start job processing until :meth:`resume` is called
:raises SchedulerAlreadyRunningError: if the scheduler is already running
:raises RuntimeError: if running under uWSGI with threads disabled
"""
if self.state != STATE_STOPPED:
raise SchedulerAlreadyRunningError

self._check_uwsgi()

with self._executors_lock:
# Create a default executor if nothing else is configured
if 'default' not in self._executors:
Expand Down Expand Up @@ -826,6 +829,14 @@ def _dispatch_event(self, event):
except BaseException:
self._logger.exception('Error notifying listener')

def _check_uwsgi(self):
"""Check if we're running under uWSGI with threads disabled."""
uwsgi_module = sys.modules.get('uwsgi')
if not getattr(uwsgi_module, 'has_threads', True):
raise RuntimeError('The scheduler seems to be running under uWSGI, but threads have '
'been disabled. You must run uWSGI with the --enable-threads '
'option for the scheduler to work.')

def _real_add_job(self, job, jobstore_alias, replace_existing):
"""
:param Job job: the job to add
Expand Down
2 changes: 2 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ APScheduler, see the :doc:`migration section <migration>`.
``YourClass.methodname`` along with an explicit ``self`` argument is no longer necessary as this
is now done automatically for you)
* Added the FAQ section to the docs
* Made ``BaseScheduler.start()`` raise a ``RuntimeError`` if running under uWSGI with threads
disabled


3.5.1
Expand Down

0 comments on commit ee7fbd6

Please sign in to comment.