summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-01-30 01:13:44 +0100
committerVictor Stinner <victor.stinner@gmail.com>2014-01-30 01:13:44 +0100
commit63c4852140064b673618b31b90d36bf5533558a2 (patch)
treef66ae9e63a4e703bb7e9f3beefe16b0d66366d69
parentc4a4623c47485dffc361f1e2e6323f3ba199ec8b (diff)
downloadtrollius-63c4852140064b673618b31b90d36bf5533558a2.tar.gz
Fix race conditions
* Remove complex code to maintain a Process.returncode attribute: replace it with a read-only property getting transport.get_returncode() * Remove _dead attribute: check the alive status using the transport instead (check if the returncode is known or not)
-rw-r--r--asyncio/subprocess.py22
1 files changed, 7 insertions, 15 deletions
diff --git a/asyncio/subprocess.py b/asyncio/subprocess.py
index 152d73a..6c4ded3 100644
--- a/asyncio/subprocess.py
+++ b/asyncio/subprocess.py
@@ -89,25 +89,17 @@ class Process:
self.stdout = protocol.stdout
self.stderr = protocol.stderr
self.pid = transport.get_pid()
- self.returncode = transport.get_returncode()
- if self.returncode is None:
- waiter = futures.Future(loop=loop)
- self._protocol._waiters.append(waiter)
- waiter.add_done_callback(self._set_returncode)
- self._dead = False
- else:
- self._dead = True
- def _set_returncode(self, fut):
- self.returncode = fut.result()
- # operations on the processing will now fail with ProcessLookupError
- self._dead = True
+ @property
+ def returncode(self):
+ return self._transport.get_returncode()
@tasks.coroutine
def wait(self):
"""Wait until the process exit and return the process return code."""
- if self.returncode is not None:
- return self.returncode
+ returncode = self._transport.get_returncode()
+ if returncode is not None:
+ return returncode
waiter = futures.Future(loop=self._loop)
self._protocol._waiters.append(waiter)
@@ -118,7 +110,7 @@ class Process:
return self._transport.get_extra_info('subprocess')
def _check_alive(self):
- if self._dead:
+ if self._transport.get_returncode() is not None:
raise ProcessLookupError()
def send_signal(self, signal):