Message346568
> See issue 36067 for a related discussion. The _active list and _cleanup function are not required in Windows. When a process exits, it gets rundown to free its handle table and virtual memory. Only the kernel object remains, which is kept alive by pointer and handle references to it that can query information such as the exit status code. As soon as the last reference is closed, the Process object is automatically reaped. It doesn't have to be waited on.
Linux (for example) has the same design: the kernel doesn't keep a "full process" alive, but a lightweight structure just for its parent process which gets the exit status. That's the concept of "zombie process".
One issue on Linux is that the zombie process keeps the pid used until the parent reads the child exit status, and Linux pids are limited to 32768 by default.
Now I'm not sure that I understand what it means on Windows. The subprocess module uses a magic Handle object which calls CloseHandle(handle) in its __del__() method. I dislike relying on destructors. If an object is kept alive by a reference cycle, it's never released: CloseHandle() isn't called.
So code spawning process should wait until subprocesses complete to ensure that CloseHandle() is called, no?
Except that Popen._internal_poll() doesn't clear the handle even after the process completes.
If Popen.__del__() doesn't add active processes to the _active list, it should at least explicitly call CloseHandle(), no? |
|
Date |
User |
Action |
Args |
2019-06-25 22:49:47 | vstinner | set | recipients:
+ vstinner, gregory.p.smith, paul.moore, tim.golden, zach.ware, eryksun, steve.dower, efiop |
2019-06-25 22:49:47 | vstinner | set | messageid: <1561502987.33.0.181782063072.issue37380@roundup.psfhosted.org> |
2019-06-25 22:49:47 | vstinner | link | issue37380 messages |
2019-06-25 22:49:47 | vstinner | create | |
|