1 |
Author: zmedico |
2 |
Date: 2009-10-03 06:10:58 +0000 (Sat, 03 Oct 2009) |
3 |
New Revision: 14477 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/portage/__init__.py |
7 |
Log: |
8 |
Don't use a fork inside _test_pty_eof() because it gives inconsistent results. |
9 |
|
10 |
|
11 |
Modified: main/trunk/pym/portage/__init__.py |
12 |
=================================================================== |
13 |
--- main/trunk/pym/portage/__init__.py 2009-10-03 04:03:16 UTC (rev 14476) |
14 |
+++ main/trunk/pym/portage/__init__.py 2009-10-03 06:10:58 UTC (rev 14477) |
15 |
@@ -3746,6 +3746,8 @@ |
16 |
Raises an EnvironmentError from openpty() if it fails. |
17 |
""" |
18 |
|
19 |
+ use_fork = False |
20 |
+ |
21 |
import array, fcntl, pty, select, termios |
22 |
test_string = 2 * "blah blah blah\n" |
23 |
test_string = _unicode_decode(test_string, |
24 |
@@ -3765,17 +3767,23 @@ |
25 |
termios.tcsetattr(slave_fd, termios.TCSANOW, mode) |
26 |
|
27 |
# Simulate a subprocess writing some data to the |
28 |
- # slave end of the pipe, and then exiting. Do a |
29 |
- # real fork here since otherwise os.close(slave_fd) |
30 |
- # would block on some platforms such as Darwin. |
31 |
- pids = process.spawn_bash(_unicode_encode("echo -n '%s'" % test_string, |
32 |
- encoding='utf_8', errors='strict'), env=os.environ, |
33 |
- fd_pipes={0:sys.stdin.fileno(), 1:slave_fd, 2:slave_fd}, |
34 |
- returnpid=True) |
35 |
- if isinstance(pids, int): |
36 |
- os.close(master_fd) |
37 |
- os.close(slave_fd) |
38 |
- raise EnvironmentError('spawn failed') |
39 |
+ # slave end of the pipe, and then exiting. |
40 |
+ # Using a fork here gave inconsistent results, |
41 |
+ # so it's disabled now. |
42 |
+ pid = None |
43 |
+ if use_fork: |
44 |
+ pids = process.spawn_bash(_unicode_encode("echo -n '%s'" % test_string, |
45 |
+ encoding='utf_8', errors='strict'), env=os.environ, |
46 |
+ fd_pipes={0:sys.stdin.fileno(), 1:slave_fd, 2:slave_fd}, |
47 |
+ returnpid=True) |
48 |
+ if isinstance(pids, int): |
49 |
+ os.close(master_fd) |
50 |
+ os.close(slave_fd) |
51 |
+ raise EnvironmentError('spawn failed') |
52 |
+ pid = pids[0] |
53 |
+ else: |
54 |
+ os.write(slave_fd, _unicode_encode(test_string, |
55 |
+ encoding='utf_8', errors='strict')) |
56 |
os.close(slave_fd) |
57 |
|
58 |
master_file = os.fdopen(master_fd, 'rb') |
59 |
@@ -3807,7 +3815,8 @@ |
60 |
data.append(_unicode_decode(buf.tostring(), |
61 |
encoding='utf_8', errors='strict')) |
62 |
|
63 |
- os.waitpid(pids[0], 0) |
64 |
+ if pid is not None: |
65 |
+ os.waitpid(pid, 0) |
66 |
master_file.close() |
67 |
|
68 |
return test_string == ''.join(data) |