Python winerror.ERROR_ALREADY_EXISTS Examples

The following are 5 code examples of winerror.ERROR_ALREADY_EXISTS(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module winerror , or try the search function .
Example #1
Source File: Mutex.py    From Crypter with GNU General Public License v3.0 6 votes vote down vote up
def __acquire(self):
        '''
        Attempts to acquire the mutex
        @raise MutexAlreadyAcquired
        '''

        mutex = win32event.CreateMutex(None, 1, self.MUTEX_NAME)
        if win32api.GetLastError() == winerror.ERROR_ALREADY_EXISTS:
            raise MutexAlreadyAcquired()

        return mutex


# ================================================================
# = MutexAlreadyAcquired Exception Class
# =============================================================== 
Example #2
Source File: test_win32api.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testLongLongPathNames(self):
        # We need filename where the FQN is > 256 - simplest way is to create a
        # 250 character directory in the cwd (except - cwd may be on a drive
        # not supporting \\\\?\\ (eg, network share) - so use temp.
        import win32file
        basename = "a" * 250
        # but we need to ensure we use the 'long' version of the
        # temp dir for later comparison.
        long_temp_dir = win32api.GetLongPathNameW(tempfile.gettempdir())
        fname = "\\\\?\\" + os.path.join(long_temp_dir, basename)
        try:
            win32file.CreateDirectoryW(fname, None)
        except win32api.error, details:
            if details.winerror!=winerror.ERROR_ALREADY_EXISTS:
                raise 
Example #3
Source File: IPC.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def create(self):
        obtain_mutex = 1
        mutex = win32event.CreateMutex(None, obtain_mutex, app_name)

        # prevent the PyHANDLE from going out of scope, ints are fine
        self.mutex = int(mutex)
        mutex.Detach()

        lasterror = win32api.GetLastError()
        
        if lasterror == winerror.ERROR_ALREADY_EXISTS:
            takeover = 0

            try:
                # if the mutex already exists, discover which port to connect to.
                # if something goes wrong with that, tell us to take over the
                # role of master
                takeover = self.discover_sic_socket()
            except:
                pass
            
            if not takeover:
                raise BTFailure(_("Global mutex already created."))

        self.master = 1

        # lazy free port code
        port_limit = 50000
        while self.port < port_limit:
            try:
                controlsocket = self.rawserver.create_serversocket(self.port,
                                                                   '127.0.0.1')
                self.controlsocket = controlsocket
                break
            except socket.error, e:
                self.port += 1 
Example #4
Source File: IPC.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def IsAnotherInstanceRunning(self):
        return winerror.ERROR_ALREADY_EXISTS == self.lasterror 
Example #5
Source File: singleinstance.py    From Email_My_PC with MIT License 5 votes vote down vote up
def aleradyrunning(self):
        return (self.lasterror == ERROR_ALREADY_EXISTS)