From ee7fbd65cb5e35ec26a50f3dbe23ba353e6b3227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Fri, 10 Aug 2018 18:50:01 +0300 Subject: [PATCH] Raise RuntimeError if starting the scheduler under uWSGI without threads --- apscheduler/schedulers/base.py | 11 +++++++++++ docs/versionhistory.rst | 2 ++ 2 files changed, 13 insertions(+) diff --git a/apscheduler/schedulers/base.py b/apscheduler/schedulers/base.py index f7c65f74d..8f910a653 100644 --- a/apscheduler/schedulers/base.py +++ b/apscheduler/schedulers/base.py @@ -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: @@ -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 diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index fc5f2d8fb..32b5843a1 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -11,6 +11,8 @@ APScheduler, see the :doc:`migration section `. ``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