Python后台任务线程locking错误与mod_wsgi

我有一个构build在Flask框架上的小型python web应用程序,并使用mod_wsgi将其部署到apache。 应用程序正在安排每隔几分钟运行一次apscheduler的后台任务。

从Apache的错误日志,我一直在观察一个错误。 这个错误似乎是在后台任务运行的时候抛出的,但是在之前或之后是不一致的,而且经常会出现在多次之后。

这是错误:

Exception ignored in: <module 'threading' from '/usr/local/lib/python3.4/threading.py'> Traceback (most recent call last): File "/usr/local/lib/python3.4/threading.py", line 1289, in _shutdown assert tlock is not None AssertionError: 

那个来自python本身的代码是这样的:

 def _shutdown(): # Obscure: other threads may be waiting to join _main_thread. That's # dubious, but some code does it. We can't wait for C code to release # the main thread's tstate_lock - that won't happen until the interpreter # is nearly dead. So we release it here. Note that just calling _stop() # isn't enough: other threads may already be waiting on _tstate_lock. tlock = _main_thread._tstate_lock # The main thread isn't finished yet, so its thread state lock can't have # been released. assert tlock is not None assert tlock.locked() tlock.release() 

我没有经验足够的multithreading或python源代码,以了解这一点,但似乎主线程的locking没有设置,或者它已被取消设置。 因为我没有在本地遇到这个错误,我怀疑这是mod_wsgi或apache。 堆栈跟踪没有包含除了导致错误的行之外的任何元素,我觉得很奇怪,尽pipe我找不到它的含义。

我没有经历这个错误的任何副作用,如果我没有查看日志,我可能不会注意到它的存在。 在将应用程序部署到运行Ubuntu 14.04.1 LTS的生产服务器之前,我从来没有见过它。 这是来自apache的版本string:

 Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.4 mod_wsgi/3.4 Python/3.4.0 

我希望有人能够理解这一点,并帮助我摆脱它。

编辑:

我现在已经将应用程序的背景任务分解了出来,但是我仍然有这个错误,所以这在mod_wsgi或者Flask中似乎是一个问题。

原来问题与apscheduler或Flask无关。 很难说究竟是什么原因,但是从源代码构buildpython --enable-shared和从pypi下载最新的mod_wsgi解决了我的问题。