Nevermind on what I said about psutil. On windows its a heavy handed operation to get a parent process id, or check if a pid exists because process management on windows is harder. So yea polling with psutil in a thread may be the only cross platform approach. I found a windows approach that mimics what psutil does, using ctypes if you want to try and avoid a dependency: http://stackoverflow.com/a/17645146/496445
On Sat, Mar 7, 2015 at 9:36 AM Justin Israel <[email protected]> wrote: > On posix, the value of the parent pid changes if it dies and the child > orphans , to either 1 or 0. Not sure what the behaviour is on Windows. You > would have to be careful about trying to poll exactly for a specific pid of > the parent since it is possible for the pid to get reused. > The actual polling should be really easy, even without psutil, just using > the "os" module and a thread. > > On Sat, 7 Mar 2015 7:58 AM Fredrik Averpil <[email protected]> > wrote: > >> I think you can poll a pid using psutil. Check out its Process class. >> >> // F >> fre 6 mar 2015 kl. 16:46 skrev Marcus Ottosson <[email protected]>: >> >> No problem, Justin, it’s not terribly obvious that it’s using pywin32 as >>> it isn’t showing up in the imports; it looks like it’s got quite a few >>> different names, all prefixed win32. >>> >>> A ctypes approach seems reasonable. Haven’t considered it beyond a few >>> non-working examples, but I bet it must be able to deal with Job >>> objects too. >>> >>> Other than that, there is one detail about my requirements which might >>> enable another method or achieving what I want; which is that the child is >>> just another Python interpreter under my control. So what I could do is >>> pass the pid of the parent to the child and have it *poll* every >>> n-seconds for whether the parent is still running. If not, clean-up and >>> self-destruct. >>> >>> Though polling a process for activity seems a challenge on it’s own.. >>> (on Windows, that is. Sigh) >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit https://groups.google.com/d/ >>> msgid/python_inside_maya/CAFRtmOCEEX84wvO1X2J4Ra9BnEMdX >>> 6HZqe%3Dk83vB4p%2B6Z0cAnw%40mail.gmail.com >>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCEEX84wvO1X2J4Ra9BnEMdX6HZqe%3Dk83vB4p%2B6Z0cAnw%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit https://groups.google.com/d/ >> msgid/python_inside_maya/CAD%3DwhWN7x857idRaX3ve2NvFiVNVG- >> zQSk2jSS2y9M55eyTOjw%40mail.gmail.com >> <https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWN7x857idRaX3ve2NvFiVNVG-zQSk2jSS2y9M55eyTOjw%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0FosprAtYFXRGRRZmGrCGAjqwK1%3DUwy8aFQNym1HyUfg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
