Richard Warfield <warfi...@gmail.com> added the comment:

Thanks for looking into this.  Changing the behavior of the
"threading" module to be consistent with the runtime and "signal" module
would be sufficient, at least for my particular case.  If the "if
threading.current_thread() is threading.main_thread()" guard worked as
expected it would be clear how to resolve the problem.

On Sat, Dec 14, 2019 at 6:25 AM Eric Snow <rep...@bugs.python.org> wrote:

>
> Eric Snow <ericsnowcurren...@gmail.com> added the comment:
>
> Before 3.8, the "signal" module checked against the thread in which the
> module was initially loaded, treating that thread as the "main" thread.
> That same was true (and still is) for the "threading" module.  The problem
> for both modules is that the Python runtime may have actually been
> initialized in a different thread, which is the actual "main" thread.
>
> Since Python 3.8 we store the ID of the thread where the runtime is
> initialized and use that in the check the "signal" module does.  However,
> the "threading" module still uses the ID of the thread where it is first
> imported.  So your check against "threading.main_thread()" must be in code
> that isn't running in the same thread where you ran Py_Initialize().  It
> probably used to work because you imported "signal" and "threading" for the
> first time in the same thread.
>
> So what next?
>
> First, I've created issue39042 to address the current different meanings
> of "main thread".  That should resolve the discrepancy between the signal
> and threading modules.
>
> Second, what can we do to help embedders make sure they are running their
> code in the main thread (e.g. when setting signals)?  Is there any C-API we
> could add which would have helped you here?
>
> ----------
> nosy: +eric.snow, vstinner
>
> _______________________________________
> Python tracker <rep...@bugs.python.org>
> <https://bugs.python.org/issue38904>
> _______________________________________
>

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38904>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to