trbs / pid

Pidfile featuring stale detection and file-locking, can also be used as context-manager or decorator
https://pypi.python.org/pypi/pid/
Apache License 2.0
102 stars 26 forks source link

2.2.4 deletes pid file while script is still running #25

Closed kaptajnen closed 5 years ago

kaptajnen commented 5 years ago

Since version 2.2.4 this library is broken. If you run the same script twice, you get the pid.PidFileAlreadyLockedError: [Errno 35] Resource temporarily unavailable error, however the pid file is also deleted and if you run the script again it will succeed even though the first instance is still running.

Below is a sample script. Run it in one terminal, then run it again twice in a separate terminal to observe the incorrect behavior.

#!/usr/bin/env python

from pid import PidFile
from time import sleep

if __name__ == '__main__':
    with PidFile('test123', piddir='/tmp'):
        sleep(9999999)
trbs commented 5 years ago

WoW thats bad. We really need to catch that in our tests. Do you think you could create a PR for a test for this ?

(Otherwise I will try to make one as soon as I can)

kaptajnen commented 5 years ago

I created a PR for a test. It's not very elegant but I couldn't figure out a better way since it needs to spawn a separate interpreter so that the atexit handler is run before the first instance finishes.

trbs commented 5 years ago

Could you please test with ce9a6e11438fb168d94c522a44f86cdd047271f4 ?

kaptajnen commented 5 years ago

I can no longer reproduce the issue, looks like that fixed it. Thanks!

trbs commented 5 years ago

Awesome !

2.2.5 is released on https://pypi.org/project/pid/ :-)