unix-ffi: Fixing behavior to avoid zombie threads.#1046
Conversation
This commit is fixing this issue: micropython#780 Now the pid of child thread will be stored and closed properly. Even with context manager. Signed-off-by: Kirill Lukonin (Evil Wireless Man) <klukonin@gmail.com>
|
bump up |
|
It would be good to add a test for this functionality, Other tests for the ffi module live in the micropython repo under tests/ports/unix you could take one of the other ffi_ tests as the base, and add example code to it. |
|
|
||
| class _PopenStream: | ||
| def __init__(self, fd, pid, mode): | ||
| self._fd = open(f"/dev/fd/{fd}", mode) |
There was a problem hiding this comment.
This needs to use builtins.open so that the returned object is a stream.
| pid, status = waitpid(self._pid, 0) | ||
| self._exitcode = status | ||
| self._closed = True | ||
| return self._exitcode |
There was a problem hiding this comment.
This _PopenStream object will need to implement read/write/etc operations, so that you can communicate with the process.
Eg prior to this patch it's possible to do:
import os
ls = os.popen("/bin/ls")
print(ls.read())
ls.close()and that still needs to work.
|
I'll update the PR. |
|
@klukonin do you have any time to update this PR based on the feedback? |
|
Yes. Sorry for the delay. |
This commit is fixing this issue:
#780
As discussed here https://github.com/orgs/micropython/discussions/13239
Now the pid of child thread will be stored and closed properly. Even with context manager.