Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
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 allRuntimeError
s.
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
Labels
Projects
Status
Status