Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mute 3.12.2 error #13831

Merged
merged 3 commits into from
Jun 9, 2024
Merged

Mute 3.12.2 error #13831

merged 3 commits into from
Jun 9, 2024

Conversation

jlowin
Copy link
Member

@jlowin jlowin commented Jun 6, 2024

Python 3.12.2 introduced an issue that our background log handlers sometimes hit when writing logs while the system is tearing down (which happens very frequently in CI and interactive runs). The issue appears to be fixed in Python 3.12.3. If the problem happens, there is no recourse and it is classified as a Python bug, not a Prefect bug, so muting this specific error will hopefully save devs from the red herring rabbit hole I spent the last day in.

@jlowin jlowin requested review from zangell44 and a team as code owners June 6, 2024 16:40
Copy link
Contributor

@bunchesofdonald bunchesofdonald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Copy link
Collaborator

@zzstoatzz zzstoatzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dang, i also went down this rabbit hole for a bit -- thank you!

@zzstoatzz
Copy link
Collaborator

just to surface some sync discussion

i still think there's a lurking problem with this part of QueueService, since even in python 3.12.3, we get the following

--- Logging error ---
Traceback (most recent call last):
  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/logging/handlers.py", line 145, in emit
    APILogWorker.instance().send(log)
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/logging/handlers.py", line 79, in instance
    return super().instance(*settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/_internal/concurrency/services.py", line 248, in instance
    cls._instances[key] = cls._new_instance(*args)
                          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/_internal/concurrency/services.py", line 268, in _new_instance
    from_sync.call_soon_in_loop_thread(create_call(instance.start)).result()
  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/_internal/concurrency/calls.py", line 312, in result
    return self.future.result(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/_internal/concurrency/calls.py", line 182, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/_internal/concurrency/calls.py", line 346, in _run_sync
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/_internal/concurrency/services.py", line 71, in start
    _register_atexit(self._at_exit)
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1559, in _register_atexit
    raise RuntimeError("can't register atexit after shutdown")
RuntimeError: can't register atexit after shutdown

@jlowin
Copy link
Member Author

jlowin commented Jun 9, 2024

@zzstoatzz good call. I'm not sure if this issue intersects that or is just extremely related to that. Nonetheless as an experiment I modified the log worker to flush in the global thread instead of a new thread; I'm curious to see the result. However even the traceback you supplied already shows the error happening when call_soon_in_loop_thread which means that it might not be related to creating new threads as much as it is interacting with them (e.g. registering atexit)

@jlowin
Copy link
Member Author

jlowin commented Jun 9, 2024

I think given that tests are passing lets merge this to close one avenue and continue exploring what @zzstoatzz surfaced separately

@jlowin jlowin merged commit da6e2ee into main Jun 9, 2024
26 checks passed
@jlowin jlowin deleted the shutdown-bug branch June 9, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants