Make _test_pty_eof() fork when writing to the slave_fd, since otherwise
authorZac Medico <zmedico@gentoo.org>
Sun, 27 Sep 2009 20:12:29 +0000 (20:12 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 27 Sep 2009 20:12:29 +0000 (20:12 -0000)
it would block on some platforms such as Darwin.

svn path=/main/trunk/; revision=14451

pym/portage/__init__.py

index 05f7b86bd34fa3c27bb10fc894efec3755a20277..3bc125b94f1cdfd01167a2447df72b7d4c240548 100644 (file)
@@ -3768,10 +3768,18 @@ def _test_pty_eof():
        termios.tcsetattr(slave_fd, termios.TCSANOW, mode)
 
        # Simulate a subprocess writing some data to the
-       # slave end of the pipe, and then exiting.
-       slave_file.write(_unicode_encode(test_string,
-               encoding='utf_8', errors='strict'))
-       slave_file.close()
+       # slave end of the pipe, and then exiting. Do a
+       # real fork here since otherwise slave_file.close()
+       # would block on some platforms such as Darwin.
+       pid = os.fork()
+       if pid == 0:
+               slave_file.write(_unicode_encode(test_string,
+                       encoding='utf_8', errors='strict'))
+               slave_file.close()
+               os._exit(os.EX_OK)
+       else:
+               slave_file.close()
+               os.waitpid(pid, 0)
 
        eof = False
        data = []