~pythonregexp2.7/python/issue2636-09-01+10

« back to all changes in this revision

Viewing changes to Lib/subprocess.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-22 21:39:45 UTC
  • mfrom: (39055.1.33 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080922213945-23717m5eiqpamcyn
Merged in changes from the Single-Loop Engine branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
411
411
    MAXFD = 256
412
412
 
413
413
# True/False does not exist on 2.2.0
414
 
try:
415
 
    False
416
 
except NameError:
417
 
    False = 0
418
 
    True = 1
 
414
#try:
 
415
#    False
 
416
#except NameError:
 
417
#    False = 0
 
418
#    True = 1
419
419
 
420
420
_active = []
421
421
 
422
422
def _cleanup():
423
423
    for inst in _active[:]:
424
 
        if inst.poll(_deadstate=sys.maxint) >= 0:
 
424
        if inst._internal_poll(_deadstate=sys.maxint) >= 0:
425
425
            try:
426
426
                _active.remove(inst)
427
427
            except ValueError:
635
635
            # We didn't get to successfully create a child process.
636
636
            return
637
637
        # In case the child hasn't been waited on, check if it's done.
638
 
        self.poll(_deadstate=sys.maxint)
 
638
        self._internal_poll(_deadstate=sys.maxint)
639
639
        if self.returncode is None and _active is not None:
640
640
            # Child is still running, keep us alive until we can wait on it.
641
641
            _active.append(self)
671
671
        return self._communicate(input)
672
672
 
673
673
 
 
674
    def poll(self):
 
675
        return self._internal_poll()
 
676
 
 
677
 
674
678
    if mswindows:
675
679
        #
676
680
        # Windows methods
842
846
                errwrite.Close()
843
847
 
844
848
 
845
 
        def poll(self, _deadstate=None):
 
849
        def _internal_poll(self, _deadstate=None):
846
850
            """Check if child process has terminated.  Returns returncode
847
851
            attribute."""
848
852
            if self.returncode is None:
1062
1066
                        os.chdir(cwd)
1063
1067
 
1064
1068
                    if preexec_fn:
1065
 
                        apply(preexec_fn)
 
1069
                        preexec_fn()
1066
1070
 
1067
1071
                    if env is None:
1068
1072
                        os.execvp(executable, args)
1112
1116
                raise RuntimeError("Unknown child exit status!")
1113
1117
 
1114
1118
 
1115
 
        def poll(self, _deadstate=None):
 
1119
        def _internal_poll(self, _deadstate=None):
1116
1120
            """Check if child process has terminated.  Returns returncode
1117
1121
            attribute."""
1118
1122
            if self.returncode is None:
1158
1162
 
1159
1163
            input_offset = 0
1160
1164
            while read_set or write_set:
1161
 
                rlist, wlist, xlist = select.select(read_set, write_set, [])
 
1165
                try:
 
1166
                    rlist, wlist, xlist = select.select(read_set, write_set, [])
 
1167
                except select.error, e:
 
1168
                    if e.args[0] == errno.EINTR:
 
1169
                        continue
 
1170
                    raise
1162
1171
 
1163
1172
                if self.stdin in wlist:
1164
1173
                    # When select has indicated that the file is writable,
1165
1174
                    # we can write up to PIPE_BUF bytes without risk
1166
1175
                    # blocking.  POSIX defines PIPE_BUF >= 512
1167
 
                    bytes_written = os.write(self.stdin.fileno(), buffer(input, input_offset, 512))
 
1176
                    chunk = input[input_offset : input_offset + 512]
 
1177
                    bytes_written = os.write(self.stdin.fileno(), chunk)
1168
1178
                    input_offset += bytes_written
1169
1179
                    if input_offset >= len(input):
1170
1180
                        self.stdin.close()