From 8f28c9009e2e71c71dad69bfe277bfe973cb49dd Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Mon, 12 Dec 2016 20:55:13 +0100 Subject: Set parent process's input stream inside the build process. (#2535) --- lib/spack/spack/package.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 31d08be456..3502eb2931 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1218,6 +1218,19 @@ class PackageBase(object): """Forked for each build. Has its own process and python module space set up by build_environment.fork().""" + # We are in the child process. This means that our sys.stdin is + # equal to open(os.devnull). Python did this to prevent our process + # and the parent process from possible simultaneous reading from + # the original standard input. But we assume that the parent + # process is not going to read from it till we are done here, + # otherwise it should not have passed us the copy of the stream. + # Thus, we are free to work with the the copy (input_stream) + # however we want. For example, we might want to call functions + # (e.g. raw_input()) that implicitly read from whatever stream is + # assigned to sys.stdin. Since we want them to work with the + # original input stream, we are making the following assignment: + sys.stdin = input_stream + start_time = time.time() if not fake: if not skip_patch: -- cgit v1.2.3-70-g09d2