Code Monkey home page Code Monkey logo

Comments (13)

masteret avatar masteret commented on August 22, 2024

I have made a commit in my fork repo of ptyprocess
masteret@420f657
If it is ok to use please allow me to create a PR

from ptyprocess.

rocmit avatar rocmit commented on August 22, 2024

I also ran into this issue. It would be great if this issue can be fixed soon!

from ptyprocess.

rocmit avatar rocmit commented on August 22, 2024

Just wanted to point out another thing that we should consider when implementing the solution...

In the same scenario, if the child is closed, terminated, or killed by process B, it will become a zombie process (PID is still valid but the process is dead)... This os.kill(pid, 0) solution would not catch that since the return would be None, instead of an exception.

The use case is like this: 1) Process A created an child session 2) Process B is created by multiprocess and it uses the same child session 3) If Process B kills the child session that was created under process A, os.kill(pid, 0) will return None and isalive will return True.

from ptyprocess.

MountainRider avatar MountainRider commented on August 22, 2024

Won't Process A successfully call os.waitpid(self.pid, waitpid_options) on the child?

from ptyprocess.

rocmit avatar rocmit commented on August 22, 2024

Yes, process A would be able to get the correct isalive() status with os.waitpid. However, if process B runs isalive check, it would run into the situation I described.

from ptyprocess.

MountainRider avatar MountainRider commented on August 22, 2024

I just verified this with some code. After Process B killed Process C, os.kill did not raise an exception.

from ptyprocess.

masteret avatar masteret commented on August 22, 2024

Thank you for the comments, I will look into the scenario and see if I can check it correctly

from ptyprocess.

MountainRider avatar MountainRider commented on August 22, 2024

Perhaps @rocmit can make an helpful suggestion.

from ptyprocess.

masteret avatar masteret commented on August 22, 2024

Since process A can get a correct isalive() status with os.waitpid
The problem only happens when non-parent process call isalive with ptyprocess pid
I can add an additional check to see if the pid is a zombie process by looking at the 3rd item in /proc/${pid}/stat
if it is Z then that means the process is a zombie, then we can assume it is not alive

from ptyprocess.

MountainRider avatar MountainRider commented on August 22, 2024

There won't be a proc file system on OS X.

from ptyprocess.

rocmit avatar rocmit commented on August 22, 2024

/proc/pid/stat file is what I use to workaround this after doing some research. Like MountainRider mentioned, this may not work on other OS.

from ptyprocess.

masteret avatar masteret commented on August 22, 2024

After some research, I found psutil has a way to determine if a proc is zombie in different os.
In Linux, it checks the proc and in OSX it uses sysctl in C.

from ptyprocess.

jquast avatar jquast commented on August 22, 2024

Yes, a maintainer here to chime in, the only thing preventing me from reviewing this PR quickly is to get FreeBSD, Linux, and mac machines to run the current tests--we may even need additional tests to cover new logic here, we'll see what the coverage report says, and/ or write some if-else conditions around platform if necessary.

from ptyprocess.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.