(Jul-20-2017, 04:10 PM)harun2525 Wrote: (Jul-19-2017, 07:59 PM)nilamo Wrote: A lockfile. Or, if you like very easy things, tendo.singleton.SingleInstance()
https://github.com/pycontribs/tendo/blob...ngleton.py
i cant' trust lockfile because this file can be deleted from other users. i heard mutex in c/c++ language to do this. does mutex avaliable in python ?
i never seen singleton before. I'll try thanks.
If a user wants to run it twice, and they're willing to delete a lockfile to accomplish it, why not just let them? At that point, they know they could have undefined behavior.
If you try the port path, but use a port that some other program out there in the world is also using, then your program might never be able to run.
If you go with check the filename from psutil, then that doesn't stop someone from creating a wrapper script and just importing your program, so the "running program" has a different name. And then there's the fact that "python.exe" is only on windows, and won't stop someone from just renaming the python binary so that your program is running through "my-personal-python-v3.6.exe" or something.
There WAS a mutex module in python, but it was removed in 3.0 (and was deprecated since 2.6):
https://docs.python.org/2/library/mutex....dule-mutex
I think using a lockfile would be the easiest way, since a determined user could just circumvent your checks anyway.