简体   繁体   中英

Python check if current process is running?

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.

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

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; eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM