GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — warnings.catch_warnings is not thread-safe · Issue #50896 · python/cpython

warnings.catch_warnings is not thread-safe #50896

New issue
Copy link
New issue
Copy link
Closed
Closed
warnings.catch_warnings is not thread-safe#50896
Copy link
Assignees
birkenfeld
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

ggenellina
mannequin
opened on Aug 5, 2009
Issue body actions
BPO 6647
Nosy @akuchling, @birkenfeld, @pitrou
Files
  • error-warnings.py: demo code showing the problem
  • warnings.diff
  • 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']

    Activity

    1. ggenellina commented on Aug 5, 2009

      @ggenellina
      ggenellinamannequin
      on Aug 5, 2009
      MannequinAuthor
      More actions

      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.

    2. ggenellina
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Aug 5, 2009
    3. pitrou commented on Aug 5, 2009

      @pitrou
      pitrou
      on Aug 5, 2009
      Member
      More actions

      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.

    4. pitrou
      added
      docsDocumentation in the Doc dirDocumentation in the Doc dir
      on Aug 5, 2009
    5. pitrou
      assigned
      birkenfeld
      on Aug 5, 2009
    6. ggenellina commented on Nov 15, 2009

      @ggenellina
      ggenellinamannequin
      on Nov 15, 2009
      MannequinAuthor
      More actions

      Document that warnings.catch_warnings is not thread safe.

    7. akuchling commented on Apr 2, 2010

      @akuchling
      akuchling
      on Apr 2, 2010
      Contributor
      More actions

      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::.

    8. akuchling
      closed this as completedon Apr 2, 2010
    9. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @birkenfeld
      birkenfeld

    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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.