I need to find a right way to prevent two running instances of my (Python) program. I am currently using the following method.
On Windows,
os.popen('wmic process get caption,processid | findstr `programname.exe`')
On Linux,
os.popen('ps x | grep `programname`')
It seems to work fine for now. Is this method correct? Can someone suggest to me a better way?
edit: Thanks for the reply guys, Is anything wrong with the above methods? I tried the pid file way for linux. What if the pid file gets deleted somehow?
On most Windows computers, you can access the Task Manager by pressing Ctrl+Shift+Esc, then clicking the Startup tab. Select any program in the list and click the Disable button if you don't want it to run on startup.
Disable multiple instances of app. In order to disable multiple instances of an app on Windows 10, you need to install a free app called SingleInstance. Go ahead and download, and run the app. The app, by default, has one app pre-configured and that's the Calculator app on Windows 10.
Multiple instances of a program mean that the program has been loaded into memory several times. (2) In object technology, a member of a class; for example, "Lassie" is an instance of the class "dog." When an instance is created, the initial values of its instance variables are assigned.
There are numerous ways:
What you need is a service (external to your application) that manages a namespace where unique ids are available & enforced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With