Skip to content

Commit 92985b5

Browse files
committed
workaround fork
1 parent 67f9820 commit 92985b5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

s3transfer/crt.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
get_callbacks,
5050
is_s3express_bucket,
5151
)
52+
import os
5253

5354
logger = logging.getLogger(__name__)
5455

@@ -67,6 +68,20 @@ def acquire_crt_s3_process_lock(name):
6768
# lock is set as a global so that it is not unintentionally garbage
6869
# collected/released if reference of the lock is lost.
6970
global CRT_S3_PROCESS_LOCK
71+
72+
def after_in_child():
73+
global CRT_S3_PROCESS_LOCK
74+
if CRT_S3_PROCESS_LOCK is not None:
75+
# the lock is not belong to the forked child process.
76+
# Release the lock after fork in child process.
77+
CRT_S3_PROCESS_LOCK.release()
78+
CRT_S3_PROCESS_LOCK = None
79+
80+
# Check if we've already registered using a function attribute
81+
if not getattr(acquire_crt_s3_process_lock, '_fork_handler_registered', False):
82+
os.register_at_fork(after_in_child=after_in_child)
83+
acquire_crt_s3_process_lock._fork_handler_registered = True
84+
7085
if CRT_S3_PROCESS_LOCK is None:
7186
crt_lock = awscrt.s3.CrossProcessLock(name)
7287
try:

0 commit comments

Comments
 (0)