-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
RuntimeError: cannot schedule new futures after interpreter shutdown for python 3.9+ #38
Comments
Thanks for reporting this! I think we definitely support 3.9 and 3.10. I tried in my local with |
I didn't mention in the issue, it worked for Python <= 3.8 my version of python 3.9:
I could reproduce it for 3.9.2:
Changing image version to 3.8 fixes issue |
I can confirm the issue @konradzagozda is having. On Python 3.9.14 and 3.10.8, I get the error "RuntimeError: cannot schedule new futures after interpreter shutdown" On Python 3.7.14 and 3.8.14, the library runs fine. This is occurring on an M1 Pro MacBook Pro running MacOS 13. Also happened on MacOS 12. Amplitude-Python version 1.1.0. Full error readout:
|
Hi @konradzagozda , @yeutterg , thanks for the feedback! I tried both Python Flask app
Python script
My env:
If this is related to your instrumentation, is it possible to share a minimal example here for us to reproduce the issue? Thanks! |
Hi @konradzagozda @yeutterg , Could you help verify if you can add a client.shutdown() or client.flush() call before application exit? This method call can schedule a task to threads pool to empty the events buffer. Optionally add a short period time (time.sleep(0.1)) after call shutdown() to give interpreter thread grace period wait the last task scheduled to threads pool. |
@bohan-amplitude I have python 3.11 and I got the same errors, is this SDK ever passed testing with versions of python that did not reach end-of-life? Based on https://github.com/amplitude/Amplitude-Python/actions/runs/3473700633 i really believe that the only version it was tested with is 3.6 which is already EOL and deprecated, pending removal even from github actions. When is @amplitude going to implement a testing pipeline that is testing with all current python versions, we already have 5 versions that are not tested with 3.7-3.11 |
I could reproduce this and seems this is an issue happening in scripts only, and only for Python version 3.9+. The runtime error is thrown at cpython/thread.py at 3.9 · python/cpython. In submit method, it checks global variable The reason for this is, in scripts run, when the main thread completes it will call the exit method, and mark the The fix for this is tricky. I tried to use the same way in thread.py file to register a method on exit, inside just call flush. That works for Python 3.9. However, that method is not available under Python 3.9, considering the version we support starts from Python 3.6, we can’t do that now. I also tried the module method atexit in Python as an alternative, however, that is giving me the same error in Python 3.9. It seems so far there is not a good and quick way to resolve this script-specific issue. (unless we consider changing the way of threads pool and rewriting the whole threading logic, which means a much higher investment. Welcome any suggestions or any other thoughts for this.) To temporarily alleviate this issue, I would suggest calling the Please let us know if these could help and feel free to share more feedback or suggestions. |
Following up on the previous context, I put a temp workaround solution for this at #43. Feel free to share any feedback on it. Tested this on Python 3.9 and seems working fine for the script case. |
We just released v1.1.1 including the above fix. Feel free to upgrade and let us know if the experience is improved or not. Thanks for everyone's feedback! |
After upgrading to 1.1.1 we didn't see this error for a while, but unfortunately we just got two instances of it. The stacktrace is unchanged (modulo the line numbers moving around a little bit). It seems like it's still an issue, but less common now. |
Hi @simon-weber, thanks for the feedback. Would you mind sharing more details about how to reproduce in your case? We can dive more into it. Thank you. |
I don't think I've got anything too insightful to share, unfortunately. It's running under gunicorn/django on Heroku, and the errors seem to happen when dynos get shut down. |
Hi @simon-weber we are still unable to reproduce this issue. I am going to close but please reopen if you can provide steps to reproduce. Thank you. Possible issues:
|
Current Behavior
I got this stack trace when I wanted to follow SDK intro using python 3.9 or 3.10 - resulting in event not being sent
Possible Solution
There are workarounds like these https://stackoverflow.com/questions/70673175/runtimeerror-cannot-schedule-new-futures-after-interpreter-shutdown
but I think I should be able to follow introduction without going into these
Steps to reproduce
Environment
I don't know if this is related to the way I run the script? Does that mean python 3.9 and 3.10 are not supported?
The text was updated successfully, but these errors were encountered: