This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients ncoghlan, pitrou, vstinner
Date 2013-08-15.10:14:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1376561660.51.0.498019291184.issue18746@psf.upfronthosting.co.za>
In-reply-to
Content
The following test fails on FreeBSD buildbot:

    def test_finalize_with_trace(self):
        # Issue1733757
        # Avoid a deadlock when sys.settrace steps into threading._shutdown
        assert_python_ok("-c", """if 1:
            import sys, threading

            # A deadlock-killer, to prevent the
            # testsuite to hang forever
            def killer():
                import os, time
                time.sleep(2)
                print('program blocked; aborting')
                os._exit(2)
            t = threading.Thread(target=killer)
            t.daemon = True
            t.start()

            # This is the trace function
            def func(frame, event, arg):
                threading.current_thread()
                return func

            sys.settrace(func)
            """)

I ran it manually on my FreeBSD 9.1 VM, I get the following error. I don't know if it's the same error than the buildbot.
----
(...)
# clear builtins._
(...)
# restore sys.stderr
# cleanup __main__
# cleanup[1] _sysconfigdata
(...)
# cleanup[1] threading
Exception ignored in: <function WeakSet.__init__.<locals>._remove at 0x801b11058>
Traceback (most recent call last):
  File "/usr/home/haypo/prog/python/default/Lib/_weakrefset.py", line 38, in _remove
  File "x.py", line 17, in func
AttributeError: 'NoneType' object has no attribute 'current_thread'
# cleanup[1] _weakrefset
(...)
# cleanup[3] _codecs
PyThreadState_Clear: warning: thread still has a frame
----

The weakref is probably threading._dangling.

IMO Py_Finalize() should first clear the trace function. Tracing Python exception while Python is dying (exiting) is insane. I'm surprised that it works :-)
History
Date User Action Args
2013-08-15 10:14:20vstinnersetrecipients: + vstinner, ncoghlan, pitrou
2013-08-15 10:14:20vstinnersetmessageid: <1376561660.51.0.498019291184.issue18746@psf.upfronthosting.co.za>
2013-08-15 10:14:20vstinnerlinkissue18746 messages
2013-08-15 10:14:19vstinnercreate