agronholm / pythonfutures

Backport of the concurrent.futures package to Python 2.6 and 2.7
Other
232 stars 51 forks source link

atexit hooks are wrongly used #33

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I do not know how to reproduce with small program, but when using tornado 
tests, I receive that:

--------------------------------
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/mmarkk/.local/lib/python2.7/site-packages/concurrent/futures/process.py", line 82, in _python_exit
    items = list(_threads_queues.items())
AttributeError: 'NoneType' object has no attribute 'items'
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/mmarkk/.local/lib/python2.7/site-packages/concurrent/futures/thread.py", line 41, in _python_exit
    items = list(_threads_queues.items())
AttributeError: 'NoneType' object has no attribute 'items'
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/mmarkk/.local/lib/python2.7/site-packages/concurrent/futures/thread.py", line 41, in _python_exit
    items = list(_threads_queues.items())
AttributeError: 'NoneType' object has no attribute 'items'
---------------------------

But this problem is easily fixed with that:

--- process.py  2015-01-21 15:27:49.458086156 +0500
+++ process.py.new  2015-01-21 15:28:10.906259116 +0500
@@ -76,7 +76,7 @@
 _threads_queues = weakref.WeakKeyDictionary()
 _shutdown = False

-def _python_exit():
+def _python_exit(_threads_queues=_threads_queues):
     global _shutdown
     _shutdown = True
     items = list(_threads_queues.items())

!!!!! and exactly the same for threads.py !!!!

What the hell? I do not know how the _threads_queues may become None.

Original issue reported on code.google.com by socketp...@gmail.com on 21 Jan 2015 at 10:29

agronholm commented 9 years ago

Need code to reproduce this.

hachreak commented 9 years ago

@agronholm I have the same problem. You can reproduce using Invenio maint-2.0 branch and devscripts to install a virtual machine. Follow the instruction to install it and the start tests:

pip install futures
git checkout maint-2.0
find . -name "*.pyc" -exec rm '{}' \;
pip install -e .[docs] --upgrade
inveniomanage database recreate --yes-i-know
python setup.py test

This is the error:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/concurrent/futures/process.py", line 76, in _python_exit
    items = list(_threads_queues.items())
AttributeError: 'NoneType' object has no attribute 'items'
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/concurrent/futures/thread.py", line 35, in _python_exit
    items = list(_threads_queues.items())
AttributeError: 'NoneType' object has no attribute 'items'
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/home/vagrant/.virtualenvs/invenio2/local/lib/python2.7/site-packages/concurrent/futures/thread.py", line 35, in _python_exit
    items = list(_threads_queues.items())
AttributeError: 'NoneType' object has no attribute 'items'
agronholm commented 9 years ago

I've committed a changeset that should eliminate these errors. Please try the latest version from master and see if it works for you.

agronholm commented 9 years ago

Fixed in 135add7.