Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Checking forsys.is_finalizing before thread.start() still yields "can't create new thread at interpreter shutdown" #114570

Open
@Jibola

Description

@Jibola

Bug report

Bug description:

We have code inpymongo OurMongoClient object immediately spawns a new daemon thread to run some periodic check operations from the moment it is initialized. When run on python 3.12, we've run into the issuecan't create new thread at interpreter shutdown because we have casesthread.start() that can execute as the interpreter is shutting down.

To mitigate this issue we attempted checkingsys.is_finalizing before issuing thestart() call:

ifnotsys.is_finalizing():thread.start()

This still generated the same runtime error.

We tried catching theRuntimeError exception:

try:thread.start()exceptRuntimeError:pass

This worked. This feels too broad a solution than the above since it will catch and ignore allRuntimeErrors.

Finally we decided to see if we could checksys.is_finalizing after the exception is raised.

try:thread.start()exceptRuntimeError:ifsys.is_finalizing():self._thread=Nonereturnraise

To our surprise, this also failed. I can understand that starting a thread on interpreter shutdown should be avoided, but this also feels misleading if the system isn't correctly seeing--which is my assumption on whatsys.is_finalizing()--that it is experiencing interpreter shutdown.

Should the expectation not be thatsys.is_finalizing is updated before thethread.start() is called OR by the time theRuntimeError is raised? This way we can safely catch or preempt the error before triggering?

As a general inquiry, though, what should be the general best practice for patching issues like this on our end as it has introduced somewhat breaking behavior from 3.11 -> 3.12? Should we do like above with catching theRuntimeError but additionally check the exception string for the exact type ofRuntimeError?

CPython versions tested on:

3.12

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Todo

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp