Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

unix-ffi: Fixing behavior to avoid zombie threads.#1046

Open
klukonin wants to merge 1 commit intomicropython:master from
klukonin:patch-1
Open

unix-ffi: Fixing behavior to avoid zombie threads. #1046
klukonin wants to merge 1 commit intomicropython:master from
klukonin:patch-1

Conversation

@klukonin
Copy link

@klukonin klukonin commented Sep 25, 2025
edited
Loading

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.

hodan121 reacted with thumbs up emoji
@klukonin klukonin changed the title (削除) unix-ffi: Fixing behavior to avoid zombie threads (削除ここまで) (追記) unix-ffi: Fixing behavior to avoid zombie threads. (追記ここまで) Sep 25, 2025
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>
Copy link

bump up

Copy link
Contributor

Josverl commented Oct 20, 2025

It would be good to add a test for this functionality,
that also helps with maintaining stability over time.

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.

klukonin reacted with thumbs up emoji


class _PopenStream:
def __init__(self, fd, pid, mode):
self._fd = open(f"/dev/fd/{fd}", mode)
Copy link
Member

@dpgeorge dpgeorge Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use builtins.open so that the returned object is a stream.

klukonin reacted with thumbs up emoji
pid, status = waitpid(self._pid, 0)
self._exitcode = status
self._closed = True
return self._exitcode
Copy link
Member

@dpgeorge dpgeorge Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

klukonin reacted with thumbs up emoji
Copy link
Author

klukonin commented Dec 2, 2025

I'll update the PR.
Thanks for the ideas, folks =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dpgeorge dpgeorge dpgeorge left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /