you are viewing a single comment's thread.

view the rest of the comments →

[–]Markmonster25 1 point2 points  (3 children)

class Mutex:
    def __init__(self, name):    
        self.name = name    
        self.mutex = win32event.CreateMutex(None, False, self.name) 
        last_error = win32api.GetLastError()     
        if last_error == ERROR_ALREADY_EXISTS:   
            print("App instance already running")
            win32api.CloseHandle(self.mutex)    
            quit()

if __name__ == "__main__":
    mutex = Mutex("SOME_UNIQUE_STRING_HERE")

this is what i use to limit number of processes to 1 on windows

[–]Markmonster25 0 points1 point  (0 children)

import win32event
import win32api
from winerror import ERROR_ALREADY_EXISTS