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 njs
Recipients asvetlov, njs, yselivanov
Date 2018-10-14.07:19:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1539501586.32.0.788709270274.issue34968@psf.upfronthosting.co.za>
In-reply-to
Content
> What would make it not reentrant-safe?

Probably the most obvious example of a non-reentrant-safe operation is taking a lock. It's very natural to write code like:

def call_soon(...):
    with self._call_soon_lock:
        ...

but now imagine that inside the body of that 'with' statement, a signal arrives, so the interpreter pauses what it's doing to invoke the signal handler, and the signal handler turns around and invokes call_soon, which tries to acquire the same lock that it already holds → instant deadlock.

And this rules out quite a few of the tools you might normally expect to use in thread-safe code, like queue.Queue, since they use locks internally.

The reason I think the stdlib's call_soon is OK is that it doesn't perform any blocking operations, and the critical operation is simply 'self._ready.append(...)', which in CPython is atomic with respect to threads/signals/GC.
History
Date User Action Args
2018-10-14 07:19:46njssetrecipients: + njs, asvetlov, yselivanov
2018-10-14 07:19:46njssetmessageid: <1539501586.32.0.788709270274.issue34968@psf.upfronthosting.co.za>
2018-10-14 07:19:46njslinkissue34968 messages
2018-10-14 07:19:45njscreate