Off the top of my head, there are at least two ways to do this:
- You could make the script create an empty file in a specific location, and the other script could check for that. Note that you might have to manually remove the file if the script exits uncleanly.
- You could list all running processes, and check if the first one is among those processes. This is somewhat more brittle and platform-dependant.
An alternative hybrid strategy would be for the script to create the specific file and write it's PID (process id) to it. The runner script could read that file, and if the specified PID either wasn't running or was not the script, it could delete the file. This is also somewhat platform-dependant.
m = mmap.mmap(-1, 8, 'Global\\Spam');pid = int.from_bytes(m, 'little'). Ifpidis non-zero it can exit. Otherwise the script writes its pid to the shared memory, e.g.m[:] = os.getpid().to_bytes(8, 'little'), and continues to execute. The latter uses the name'Global\\Spam', which is a section named "Spam" that's globally visible across all Windows sessions. If you want it to be for the current session only, use'Spam'or'Local\\Spam'.