[New-bugs-announce] [issue32511] Thread primitives do not report the OS-level error on failure

Zack Weinberg report at bugs.python.org
Sun Jan 7 10:50:08 EST 2018

New submission from Zack Weinberg <zackw at panix.com>:

[_]thread.start_new_thread can fail if the underlying OS primitive fails (pthread_create / _beginthreadex), but the exception that is thrown when this happens is a generic RuntimeError (it's _called_ ThreadError in the source code, but it doesn't have its own subtype, so you can't even catch it specifically) and the OS-level error code is lost.  It should instead throw (an appropriate subclass of) OSError and capture the error code, like when other OS primitives fail.

Reading through the code, it looks like _all_ of the threading code has this problem - throughout [_]threadmodule.c, thread.c, and thread_pthread.h, I see error codes being dropped on the floor or at best reported with perror or dprintf, not properly captured in an OSError.

This affects all maintained versions of Python, but sadly I expect it's messy enough to fix that it's only practical to do so on trunk.

components: Library (Lib)
messages: 309623
nosy: zwol
priority: normal
severity: normal
status: open
title: Thread primitives do not report the OS-level error on failure
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list