diff options
author | alalazo <massimiliano.culpo@googlemail.com> | 2016-07-12 10:39:20 +0200 |
---|---|---|
committer | alalazo <massimiliano.culpo@googlemail.com> | 2016-07-13 09:27:09 +0200 |
commit | 440e71ff13d86856680257b282d016018101dd37 (patch) | |
tree | 18efa0c0321c96b2720e7f50afef24adce51b7fb /lib | |
parent | 857d7bfe0ff1cd56d3c2b40dc8357ac729dcdb4e (diff) | |
download | spack-440e71ff13d86856680257b282d016018101dd37.tar.gz spack-440e71ff13d86856680257b282d016018101dd37.tar.bz2 spack-440e71ff13d86856680257b282d016018101dd37.tar.xz spack-440e71ff13d86856680257b282d016018101dd37.zip |
build_environment : moved from os.fork to multiprocessing.Process
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/build_environment.py | 47 |
1 files changed, 15 insertions, 32 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index fe5186a7d7..839991deaa 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -499,41 +499,24 @@ def fork(pkg, function, dirty=False): well. If things go well, the child exits and the parent 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: - # call the forked function. + setup_package(pkg, dirty=dirty) function() - - # Use os._exit here to avoid raising a SystemExit exception, - # which interferes with unit tests. - os._exit(0) - - except spack.error.SpackError as e: - e.die() - - 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)) + child_connection.send([None, None, None]) + except Exception as e: + child_connection.send([type(e), e, None]) + finally: + child_connection.close() + + parent_connection, child_connection = multiprocessing.Pipe() + p = multiprocessing.Process(target=child_execution, args=(child_connection,)) + p.start() + exc_type, exception, traceback = parent_connection.recv() + p.join() + if exception is not None: + raise exception class InstallError(spack.error.SpackError): |