Skip to content

Commit 4519196

Browse files
committed
process: Cache PID the same way asyncio implementation does
1 parent dbbd159 commit 4519196

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

uvloop/handles/process.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cdef class UVProcess(UVHandle):
22
cdef:
33
object _returncode
4+
object _pid
45

56
set _fds_to_close
67

uvloop/handles/process.pyx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cdef class UVProcess(UVHandle):
66
self.uv_opt_env = NULL
77
self.uv_opt_args = NULL
88
self._returncode = None
9+
self._pid = None
910
self._fds_to_close = set()
1011

1112
cdef _init(self, Loop loop, list args, dict env,
@@ -45,6 +46,11 @@ cdef class UVProcess(UVHandle):
4546

4647
self._finish_init()
4748

49+
# asyncio caches the PID in BaseSubprocessTransport,
50+
# so that the transport knows what the PID was even
51+
# after the process is finished.
52+
self._pid = (<uv.uv_process_t*>self._handle).pid
53+
4854
for fd in restore_inheritable:
4955
os_set_inheritable(fd, False)
5056

@@ -368,8 +374,7 @@ cdef class UVProcessTransport(UVProcess):
368374
return handle
369375

370376
def get_pid(self):
371-
self._ensure_alive()
372-
return (<uv.uv_process_t*>self._handle).pid
377+
return self._pid
373378

374379
def get_returncode(self):
375380
return self._returncode

0 commit comments

Comments
 (0)