mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
background: disable gc before forking
Summary: We encountered an issue where gc kicked in after forking the Python process. This cause it to trigger some Rust drop logic which hung because some cross thread locks were not in a good state. Let's just disable gc during the fork and only reenable it in the parent process. Reviewed By: quark-zju Differential Revision: D22855986 fbshipit-source-id: c3e99fb000bcd4cc141848e6362bb7773d0aad3d
This commit is contained in:
parent
417d61f4b6
commit
c35b8088ef
@ -9,6 +9,7 @@ from __future__ import absolute_import
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
import gc
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
@ -55,6 +56,11 @@ else:
|
||||
# "os.fork()".
|
||||
# 2. The "pid" variable cannot be used in the "finally" block.
|
||||
try:
|
||||
# Disable gc so the child process doesn't accidentally trigger it
|
||||
# and try to collect native objects that might depend on locks held
|
||||
# by other threads.
|
||||
gc.disable()
|
||||
|
||||
# double-fork to completely detach from the parent process
|
||||
# based on http://code.activestate.com/recipes/278731
|
||||
pid = os.fork()
|
||||
@ -116,6 +122,7 @@ else:
|
||||
# mission accomplished, this child needs to exit and not
|
||||
# continue the hg process here.
|
||||
os._exit(returncode)
|
||||
gc.enable()
|
||||
|
||||
|
||||
def runshellcommand(script, env):
|
||||
|
Loading…
Reference in New Issue
Block a user