Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up shutdown for periodic executors #305

Closed
wants to merge 1 commit into from
Closed

Fix up shutdown for periodic executors #305

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 26, 2016

Hello.

It's from a robot test that uses loop operator. FOR ${lengthOfSCHMCDXXXX} IN 35 15 36

Just temporary debug messages:

_shutdown_executors set([])
_shutdown_executors None
_shutdown_executors None

We get this error when we launch tests.

unexpected error: Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "C:\Python27\lib\site-packages\pymongo\periodic_executor.py", line 133, in _shutdown_executors
    executors = list(_EXECUTORS)
TypeError: 'NoneType' object is not iterable
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "C:\Python27\lib\site-packages\pymongo\periodic_executor.py", line 133, in _shutdown_executors
    executors = list(_EXECUTORS)
TypeError: 'NoneType' object is not iterable
Error in sys.exitfunc:

[2016.04.26-15:25:09] : accessed by C:\Python27\lib\site-packages\robot\run.py
Traceback (most recent call last):
  File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "C:\Python27\lib\site-packages\pymongo\periodic_executor.py", line 133, in _shutdown_executors
    executors = list(_EXECUTORS)
TypeError: 'NoneType' object is not iterable

test finished 20160426 15:25:09

@behackett
Copy link
Member

@ajdavis I've seen this running WinKerberos tests as well. Any idea why we have this problem in master, but seemingly not in v2.9?

@behackett
Copy link
Member

behackett commented Apr 26, 2016

Also, note that this only seems to happen on Windows. I've never seen it anywhere else.

@behackett
Copy link
Member

@gaal-dev what is the robot package (I don't see this in pypi) and does it spawn processes using multiprocessing or subprocess? See the note here:

https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Process.terminate

@behackett
Copy link
Member

behackett commented Apr 26, 2016

This might be related (at least for WinKerberos):

https://briandamaged.org/blog/setuptools-test-command-hates-atexit/

The sys.path manipulation mentioned in the blog post is still in the latest version of setuptools.

@behackett
Copy link
Member

Possibly related:

pypa/setuptools#38

This is why PyMongo imports multiprocessing in its setup.py, even though it doesn't use it.

@ajdavis
Copy link
Member

ajdavis commented Apr 26, 2016

Until PEP 442 was implemented in Python 3.4, the Python interpreter shutdown sequence set all module globals, like _EXECUTORS, to None before destroying the modules.

https://github.com/python/cpython/blob/2.7/Objects/moduleobject.c#L117

(Interestingly, there's a special case for names starting with underscore, which means _EXECUTORS is set to None before other names.)

In Py_Finalize, the interpreter calls call_sys_exitfunc before PyImport_Cleanup, as you'd expect it to. So I can't imagine how _EXECUTORS is None, unless your code is running in an exotic environment besides the regular Python interpreter.

Regardless, I don't see any harm accepting this patch.

@ghost
Copy link
Author

ghost commented Apr 27, 2016

And for Linux too. I'm not sure why it happens and not always repeats.

Robot Framework http://robotframework.org/

@ghost
Copy link
Author

ghost commented May 3, 2016

Will you accept this patch?

@behackett
Copy link
Member

Hi @gaal-dev, we probably will accept your patch for the next release of PyMongo, but I want to spend some time trying to understand why this happens in the first place (global variables shouldn't be set to None before atexit runs). This is a cosmetic problem either way.

trbs added a commit to django-extensions/django-extensions that referenced this pull request Jun 25, 2016
but disable scanning django_extensions/mmongodb/ for test
since an issue with pymongo db; see mongodb/mongo-python-driver#305
results in the following annoying error:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/Users/sqrbass/Projects/django-extensions/.tox/py27-dj19/lib/python2.7/site-packages/pymongo/periodic_executor.py", line 130, in _shutdown_executors
    executors = list(_EXECUTORS)
TypeError: 'NoneType' object is not iterable
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/Users/sqrbass/Projects/django-extensions/.tox/py27-dj19/lib/python2.7/site-packages/pymongo/periodic_executor.py", line 130, in _shutdown_executors
    executors = list(_EXECUTORS)
TypeError: 'NoneType' object is not iterable
@jness
Copy link

jness commented Jul 11, 2016

This pull request has resolved my PyMongo unittest issue, can't wait to see it merged!

Thanks

@behackett
Copy link
Member

Thanks for reminding me about this. I've merged it to master.

@behackett behackett closed this Jul 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants