can't register atexit after shutdown thrown in Python 3.9
See original GitHub issueDescribe the bug
When attempting to create an s3 session resource running on python 3.9 function call throws with message can't register atexit after shutdown
Behaves as expected in python 3.8
Expected Behavior
When running in python 3.9
the following code (assuming valid values) results in s3 being a resource
session = boto3.Session(
aws_access_key_id=public_key,
aws_secret_access_key=secret_key,
)
s3 = session.resource('s3', region_name=aws_region)
Current Behavior
When running in python 3.9
the following code (assuming valid values) results in an Exception
session = boto3.Session(
aws_access_key_id=public_key,
aws_secret_access_key=secret_key,
)
s3 = session.resource('s3', region_name=aws_region)
Reproduction Steps
Run the following in python 3.9 with public_key
, secret_key
, and aws_region
set to valid values
def x():
session = boto3.Session(
aws_access_key_id=public_key,
aws_secret_access_key=secret_key,
)
s3 = session.resource('s3', region_name=aws_region)
Timer(0.5, x).start()
Possible Solution
Run with python 3.8? Error does not occur.
Additional Information/Context
No response
SDK version used
1.21.38
Environment details (OS name and version, etc.)
Mac OS 12.3.1, Python 3.9
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
server in a thread (Python3.9.0+aiohttp) : RuntimeError: can't ...
server in a thread (Python3.9.0+aiohttp) : RuntimeError: can't register atexit after shutdown ; import asyncio import threading from ; import web ...
Read more >[Example code]-server in a thread (Python3.9.0+aiohttp)
Coding example for the question server in a thread (Python3.9.0+aiohttp) : RuntimeError: can't register atexit after shutdown.
Read more >can't register atexit after shutdown - You.com | The AI Search ...
When attempting to create an s3 session resource running on python 3.9 function call throws with message can't register atexit after shutdown.
Read more >Issue 42647: Unable to use concurrent.futures in atexit hook
RuntimeError: can't register atexit after shutdown What's happening is that the ddtrace library registers an atexit hook that does an HTTP call.
Read more >can't register atexit after shutdown - Google Groups
Most of the people reading this GlowScript forum use Web VPython, without installing Python. I unfortunately know nothing about pycharm. Bruce.
Read more >Top Related Medium Post
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @relativityboy, thanks for bringing this to our attention. This appears to be an issue specific to the S3 resource. I wasn’t able to reproduce it on other resources (ec2, dynamodb, etc). There was a change in Python 3.9 to prevent daemon threads in concurrent.futures due to unexpected behaviors with subprocesses.
We’ll need more investigation but from first glance this is likely an issue with the transfer module or
s3transfer
itself. It’ll need a deep dive to understand what’s conflicting.I have another example of this that is occurring with a highly upvoted SO answer for uploading logs to S3 using atexit.register to register the uploader function during python shutdown. I suspect this registered hook is being cloned into some sort of multiprocessing under the hood and it’s attempting to call the hook for every subprocess (thread?).
Here is the SO answer that appears to now be a broken pattern: https://stackoverflow.com/a/51070892/2970906
Code sample below to reproduce:
Python 3.9.9 boto 1.21.42