py
py copied to clipboard
Expand conditions for recognizing main process
Fork failures are not uncommon on Cygwin, which causes an exception in the constructor.
Unfortunately, cleaning up the partially-initialized instance calls the __del__ method,
which then raises another exception because self.pid never got set.
This change should prevent the second exception.
Another option is to change it to
if getattr(self, "pid", None) is not None:
Hi @DWesl,
Am I correct that this is a bug report by way of pytest-forked, which uses py.process? I'm asking because, given that the py library is deprecated, a better outcome would be to update pytest-forked and other projects to not use py.process. The usual process is to copy/paste the relevant py code, and simplify it for the given use case.
I think testing this would require mocking os.fork to raise an exception, which is not something I know how to do. I'll need a bit to research that.
This was uncovered while running pytest-forked. I'm preparing another PR for them and can move this file to pytest-forked as part of that.