3

I have a small python web application built on the Flask framework and deployed with mod_wsgi to apache. The application is scheduling a background task with apscheduler that runs every couple of minutes.

From the error log of apache I have been observing an error. The error seems to be thrown around the time the background task is running, but it is not consistent to be before or after, and often it comes multiple times after each other.

Here is the error:

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:

The code at that location, which is from python itself, is this:

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

I am not experienced enough in either multi threading or the python source code to make much sense of this, but it seems the lock for the main thread is not set, or that it have been unset by something. Because I didn't encounter this error locally, I suspect this something is mod_wsgi or apache. The stack trace doesn't contain any elements other than the line wich causes the error, which I find strange although I can't find out what it means.

I haven't experienced any side effects of this error, and I probably wouldn't have noticed it existed if I hadn't looked in the logs. I did never see it before I deployed my application to the production server, which is running Ubuntu 14.04.1 LTS. Here is the version string from apache:

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

I hope someone can make any sense of this, and help me get rid of it.

EDIT:

I have now factored the background task out of the application, but I'm still having the error, so this seems like a problem in mod_wsgi or Flask.

totokaka
  • 202
  • 2
  • 8

1 Answers1

1

Turns out the problem is not related to apscheduler or Flask. It's hard to say what the exact cause was, but building python from source with --enable-shared and downloading latest mod_wsgi from pypi fixed my problems.

totokaka
  • 202
  • 2
  • 8
  • 1
    I must say, I hate it when the solution to a problem is to update and/or build the problematic program from source. – totokaka Dec 29 '14 at 19:51