Repository navigation
Closed
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
| BPO | 6647 |
|---|---|
| Nosy | @akuchling, @birkenfeld, @pitrou |
| Files |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2010-04-02.17:54:34.865>
created_at = <Date 2009-08-05.04:52:59.012>
labels = ['type-bug', 'library', 'docs']
title = 'warnings.catch_warnings is not thread-safe'
updated_at = <Date 2010-04-02.17:54:34.862>
user = 'https://bugs.python.org/ggenellina'bugs.python.org fields:
activity = <Date 2010-04-02.17:54:34.862>
actor = 'akuchling'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2010-04-02.17:54:34.865>
closer = 'akuchling'
components = ['Documentation', 'Library (Lib)']
creation = <Date 2009-08-05.04:52:59.012>
creator = 'ggenellina'
dependencies = []
files = ['14654', '15341']
hgrepos = []
issue_num = 6647
keywords = ['patch']
message_count = 4.0
messages = ['91301', '91318', '95285', '102185']
nosy_count = 4.0
nosy_names = ['akuchling', 'georg.brandl', 'ggenellina', 'pitrou']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue6647'
versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
ggenellina commentedon Aug 5, 2009
warnings.catch_warnings is a context manager supposed to save and
restore warnings filters, and optionally record all warnings issued.
But it does so in a completely thread-unsafe way, by replacing the
module's "showwarning" and "filters" attributes on enter, and restoring
them on exit. If the __enter__ / __exit__ calls of two threads overlap,
after leaving the last block the warnings state is not the same as the
original state, as it should be.
I don't know how to fix this, other than using locks (that could block
indefinitely) or severely restricting how catch_warnings may be used.
At least, this issue should be documented.
pitrou commentedon Aug 5, 2009
Any function whose purpose is to mutate global (non thread-local) state
is inherently "thread-unsafe". The only reasonable possibility is to
document it as such.
ggenellina commentedon Nov 15, 2009
Document that warnings.catch_warnings is not thread safe.
akuchling commentedon Apr 2, 2010
Added a warning to 2.x trunk in r79607, and Gabriel's doc change in r79608. This thread-unsafety seems specialized and rarely of great importance, so I used the note:: directive, not warning::.