Skip to content

workaround fork for CRT #337

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

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions s3transfer/crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import logging
import os
import re
import threading
from io import BytesIO
Expand Down Expand Up @@ -67,6 +68,22 @@ def acquire_crt_s3_process_lock(name):
# lock is set as a global so that it is not unintentionally garbage
# collected/released if reference of the lock is lost.
global CRT_S3_PROCESS_LOCK

def after_in_child():
global CRT_S3_PROCESS_LOCK
if CRT_S3_PROCESS_LOCK is not None:
# the lock is not belong to the forked child process.
# Release the lock after fork in child process.
CRT_S3_PROCESS_LOCK.release()
CRT_S3_PROCESS_LOCK = None

# Check if we've already registered using a function attribute
if not getattr(
acquire_crt_s3_process_lock, '_fork_handler_registered', False
):
os.register_at_fork(after_in_child=after_in_child)
acquire_crt_s3_process_lock._fork_handler_registered = True

if CRT_S3_PROCESS_LOCK is None:
crt_lock = awscrt.s3.CrossProcessLock(name)
try:
Expand Down