AustinM
AustinM

Reputation: 803

Check if current process is running using Python?

I need to add a function to my python script that checks if the current script is already running. If it is then it will quit, if not it continues running the script. I've looked into methods of doing this but I cant figure out how to do it.

Upvotes: 5

Views: 5696

Answers (2)

Fred Nurk
Fred Nurk

Reputation: 14212

You need to communicate using a shared resource. In the simplest sense, you use the resource as a mutex. Lock or pid files are commonly used this way on *nix by using the filesystem as that shared resource.

Depending on need, you can use a shared resource that allows communication; e.g. a web browser executed to open a given URL will communicate the URL to an existing process, if there is one.

The type of shared resources available is platform-specific.

Upvotes: 1

Drake Guan
Drake Guan

Reputation: 15122

I think you mean "cross-platform single instance of application written in python". Try this workable solution: Python: single instance of program

Upvotes: 9

Related Questions