New submission from Zack Weinberg <>:

[_]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 <>
Python-bugs-list mailing list

Reply via email to