build_environment : moved from os.fork to multiprocessing.Process
This commit is contained in:
parent
857d7bfe0f
commit
440e71ff13
@ -499,41 +499,24 @@ def child_fun():
|
|||||||
well. If things go well, the child exits and the parent
|
well. If things go well, the child exits and the parent
|
||||||
carries on.
|
carries on.
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
pid = os.fork()
|
|
||||||
except OSError as e:
|
|
||||||
raise InstallError("Unable to fork build process: %s" % e)
|
|
||||||
|
|
||||||
if pid == 0:
|
|
||||||
# Give the child process the package's build environment.
|
|
||||||
setup_package(pkg, dirty=dirty)
|
|
||||||
|
|
||||||
|
def child_execution(child_connection):
|
||||||
try:
|
try:
|
||||||
# call the forked function.
|
setup_package(pkg, dirty=dirty)
|
||||||
function()
|
function()
|
||||||
|
child_connection.send([None, None, None])
|
||||||
|
except Exception as e:
|
||||||
|
child_connection.send([type(e), e, None])
|
||||||
|
finally:
|
||||||
|
child_connection.close()
|
||||||
|
|
||||||
# Use os._exit here to avoid raising a SystemExit exception,
|
parent_connection, child_connection = multiprocessing.Pipe()
|
||||||
# which interferes with unit tests.
|
p = multiprocessing.Process(target=child_execution, args=(child_connection,))
|
||||||
os._exit(0)
|
p.start()
|
||||||
|
exc_type, exception, traceback = parent_connection.recv()
|
||||||
except spack.error.SpackError as e:
|
p.join()
|
||||||
e.die()
|
if exception is not None:
|
||||||
|
raise exception
|
||||||
except:
|
|
||||||
# Child doesn't raise or return to main spack code.
|
|
||||||
# Just runs default exception handler and exits.
|
|
||||||
sys.excepthook(*sys.exc_info())
|
|
||||||
os._exit(1)
|
|
||||||
|
|
||||||
else:
|
|
||||||
# Parent process just waits for the child to complete. If the
|
|
||||||
# child exited badly, assume it already printed an appropriate
|
|
||||||
# message. Just make the parent exit with an error code.
|
|
||||||
pid, returncode = os.waitpid(pid, 0)
|
|
||||||
if returncode != 0:
|
|
||||||
message = "Installation process had nonzero exit code : {code}"
|
|
||||||
strcode = str(returncode)
|
|
||||||
raise InstallError(message.format(code=strcode))
|
|
||||||
|
|
||||||
|
|
||||||
class InstallError(spack.error.SpackError):
|
class InstallError(spack.error.SpackError):
|
||||||
|
Loading…
Reference in New Issue
Block a user