def singleinstance(name): ''' Return True if no other instance of the application identified by name is running, False otherwise. @param name: The name to lock. @type name: string ''' if iswindows: mutexname = 'mutexforsingleinstanceof'+__appname__+name mutex = win32event.CreateMutex(None, False, mutexname) err = win32api.GetLastError() if err == winerror.ERROR_ALREADY_EXISTS: # Close this handle other wise this handle will prevent the mutex # from being deleted when the process that created it exits. win32api.CloseHandle(mutex) elif mutex and err != winerror.ERROR_INVALID_HANDLE: atexit.register(win32api.CloseHandle, mutex) return not err == winerror.ERROR_ALREADY_EXISTS else: path = os.path.expanduser('~/.'+__appname__+'_'+name+'.lock') try: f = open(path, 'w') fcntl.lockf(f.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB) atexit.register(_clean_lock_file, f) return True except IOError: return False return False
def singleinstance(name): mutexname = 'mutexforsingleinstanceof' + __appname__ + name mutex = win32event.CreateMutex(None, False, mutexname) err = win32api.GetLastError() if err == winerror.ERROR_ALREADY_EXISTS: # Close this handle other wise this handle will prevent the mutex # from being deleted when the process that created it exits. win32api.CloseHandle(mutex) elif mutex and err != winerror.ERROR_INVALID_HANDLE: atexit.register(win32api.CloseHandle, mutex) return not err == winerror.ERROR_ALREADY_EXISTS