Skip to content

Python 3.12 support - RuntimeError聽#2299

Description

@Toaster192

Problem Statement

Tried using sentry with python 3.12. Ran into newly implemented RuntimeError tests. Want to give a heads up for once there is 3.12 (hopefuly after 3.11 #1950 馃 ) support that this is something that will probably need fixing(?)

Example traceback (source):

Exception ignored in atexit callback: <function AtexitIntegration.setup_once.<locals>._shutdown at 0x7fa77fa24e00>
Traceback (most recent call last):
  File "/builds/4704997395/software/venv/lib64/python3.12/site-packages/sentry_sdk/integrations/atexit.py", line 61, in _shutdown
    client.close(callback=integration.callback)
  File "/builds/4704997395/software/venv/lib64/python3.12/site-packages/sentry_sdk/client.py", line 580, in close
    self.flush(timeout=timeout, callback=callback)
  File "/builds/4704997395/software/venv/lib64/python3.12/site-packages/sentry_sdk/client.py", line 604, in flush
    self.transport.flush(timeout=timeout, callback=callback)
  File "/builds/4704997395/software/venv/lib64/python3.12/site-packages/sentry_sdk/transport.py", line 525, in flush
    self._worker.submit(lambda: self._flush_client_reports(force=True))
  File "/builds/4704997395/software/venv/lib64/python3.12/site-packages/sentry_sdk/worker.py", line 117, in submit
    self._ensure_thread()
  File "/builds/4704997395/software/venv/lib64/python3.12/site-packages/sentry_sdk/worker.py", line 42, in _ensure_thread
    self.start()
  File "/builds/4704997395/software/venv/lib64/python3.12/site-packages/sentry_sdk/worker.py", line 70, in start
    self._thread.start()
  File "/builds/4704997395/software/venv/lib64/python3.12/site-packages/sentry_sdk/integrations/threading.py", line 56, in sentry_start
    return old_start(self, *a, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/threading.py", line 971, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't create new thread at interpreter shutdown

cpython commit adding this "detection": python/cpython@ce558e6

Solution Brainstorm

Some sort of "graceful shutdown" on exit perhaps?

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 馃憖on Aug 8, 2023
  2. Toaster192 commented on Aug 8, 2023

    @Toaster192
    Author

    We got to work around this by closing sentry manually at the end of our programs 馃し

  3. sentrivana commented on Aug 8, 2023

    @sentrivana
    Contributor

    Thanks for the heads up @Toaster192!

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 馃憖on Aug 8, 2023
  5. jnoordsij commented on Oct 3, 2023

    @jnoordsij

    Would be great to have this fixed now that Python 3.12 is officially released.

  6. moved this to Waiting for: Product Owner in GitHub Issues with 馃憖on Oct 3, 2023
  7. 14 remaining items

  8. moved this from Waiting for: Product Owner to No status in GitHub Issues with 馃憖on Oct 16, 2023
  9. ethrgeist commented on Oct 20, 2023

    @ethrgeist

    This also occurs when running migrations in Django.

    python .\src\manage.py migrate
    2023-10-20 09:44:42,475 DEBUG __init__: couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
    Operations to perform:
      Apply all migrations: <bunch of apps>
    Running migrations:
      No migrations to apply.
    Exception ignored in atexit callback: <function AtexitIntegration.setup_once.<locals>._shutdown at 0x000001F382D9B380>
    Traceback (most recent call last):
      File "C:\Users\user\.virtualenvs\sad-django\Lib\site-packages\sentry_sdk\integrations\atexit.py", line 61, in _shutdown
        client.close(callback=integration.callback)
      File "C:\Users\user\.virtualenvs\sad-django\Lib\site-packages\sentry_sdk\client.py", line 618, in close
        self.flush(timeout=timeout, callback=callback)
      File "C:\Users\user\.virtualenvs\sad-django\Lib\site-packages\sentry_sdk\client.py", line 646, in flush
        self.transport.flush(timeout=timeout, callback=callback)
      File "C:\Users\user\.virtualenvs\sad-django\Lib\site-packages\sentry_sdk\transport.py", line 549, in flush
        self._worker.submit(lambda: self._flush_client_reports(force=True))
      File "C:\Users\user\.virtualenvs\sad-django\Lib\site-packages\sentry_sdk\worker.py", line 117, in submit
        self._ensure_thread()
      File "C:\Users\user\.virtualenvs\sad-django\Lib\site-packages\sentry_sdk\worker.py", line 42, in _ensure_thread
        self.start()
      File "C:\Users\user\.virtualenvs\sad-django\Lib\site-packages\sentry_sdk\worker.py", line 70, in start
        self._thread.start()
      File "C:\Users\user\.virtualenvs\sad-django\Lib\site-packages\sentry_sdk\integrations\threading.py", line 56, in sentry_start
        return old_start(self, *a, **kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "c:\users\user\.pyenv\pyenv-win\versions\3.12.0\Lib\threading.py", line 971, in start
        _start_new_thread(self._bootstrap, ())
    RuntimeError: can't create new thread at interpreter shutdown
    
  10. moved this to Waiting for: Product Owner in GitHub Issues with 馃憖on Oct 20, 2023
  11. ThiefMaster commented on Oct 20, 2023

    @ThiefMaster

    Yes, I think it always happens when the Python interpreter exits while the sentry SDK is 'active'...

  12. antonpirker commented on Oct 23, 2023

    @antonpirker
    Contributor

    Thanks for all the input! We will try to tackle this soon!

  13. moved this from Waiting for: Product Owner to No status in GitHub Issues with 馃憖on Oct 23, 2023
  14. self-assigned this
    on Oct 23, 2023
  15. antonpirker commented on Oct 31, 2023

    @antonpirker
    Contributor

    Hey everybody,
    we just released an update that should fix this problem: https://github.com/getsentry/sentry-python/releases/tag/1.33.0

    Could you give it a try @Toaster192 @robd003 and @ethrgeist ?

  16. ethrgeist commented on Oct 31, 2023

    @ethrgeist

    Looks good, CLI and reload spam is gone, thank you very much!

  17. shikharvaish28 commented on Apr 1, 2024

    @shikharvaish28

    Hi team, I am getting this error everytime a program has to exit:

    I am using python 3.12 and sentry-sdk==1.14.0

    Exception ignored in atexit callback: <function AtexitIntegration.setup_once.<locals>._shutdown at 0x7f1cc3949940>
    Traceback (most recent call last):
      File "/opt/dataDumper/myenv/lib/python3.12/site-packages/sentry_sdk/integrations/atexit.py", line 62, in _shutdown
        client.close(callback=integration.callback)
      File "/opt/dataDumper/myenv/lib/python3.12/site-packages/sentry_sdk/client.py", line 482, in close
        self.flush(timeout=timeout, callback=callback)
      File "/opt/dataDumper/myenv/lib/python3.12/site-packages/sentry_sdk/client.py", line 504, in flush
        self.transport.flush(timeout=timeout, callback=callback)
      File "/opt/dataDumper/myenv/lib/python3.12/site-packages/sentry_sdk/transport.py", line 492, in flush
        self._worker.submit(lambda: self._flush_client_reports(force=True))
      File "/opt/dataDumper/myenv/lib/python3.12/site-packages/sentry_sdk/worker.py", line 113, in submit
        self._ensure_thread()
      File "/opt/dataDumper/myenv/lib/python3.12/site-packages/sentry_sdk/worker.py", line 42, in _ensure_thread
        self.start()
      File "/opt/dataDumper/myenv/lib/python3.12/site-packages/sentry_sdk/worker.py", line 70, in start
        self._thread.start()
      File "/opt/dataDumper/myenv/lib/python3.12/site-packages/sentry_sdk/integrations/threading.py", line 54, in sentry_start
        return old_start(self, *a, **kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.12/threading.py", line 992, in start
        _start_new_thread(self._bootstrap, ())
    RuntimeError: can't create new thread at interpreter shutdown
    
  18. ddelange commented on Apr 1, 2024

    @ddelange

    the fix was released in 1.33.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions