mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2598 (Calibre 0.6b6 Crash While Converting)
This commit is contained in:
parent
cab5e4f95c
commit
78cd647c6e
@ -14,11 +14,11 @@ class LockError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class ExclusiveFile(object):
|
class ExclusiveFile(object):
|
||||||
|
|
||||||
def __init__(self, path, timeout=10):
|
def __init__(self, path, timeout=15):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.file = open(self.path, 'a+b')
|
self.file = open(self.path, 'a+b')
|
||||||
self.file.seek(0)
|
self.file.seek(0)
|
||||||
@ -42,12 +42,11 @@ class ExclusiveFile(object):
|
|||||||
self.file.close()
|
self.file.close()
|
||||||
raise LockError
|
raise LockError
|
||||||
return self.file
|
return self.file
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
self.file.close()
|
|
||||||
if iswindows:
|
if iswindows:
|
||||||
win32api.CloseHandle(self.mutex)
|
win32api.CloseHandle(self.mutex)
|
||||||
|
self.file.close()
|
||||||
|
|
||||||
def _clean_lock_file(file):
|
def _clean_lock_file(file):
|
||||||
try:
|
try:
|
||||||
@ -62,10 +61,10 @@ def _clean_lock_file(file):
|
|||||||
|
|
||||||
def singleinstance(name):
|
def singleinstance(name):
|
||||||
'''
|
'''
|
||||||
Return True if no other instance of the application identified by name is running,
|
Return True if no other instance of the application identified by name is running,
|
||||||
False otherwise.
|
False otherwise.
|
||||||
@param name: The name to lock.
|
@param name: The name to lock.
|
||||||
@type name: string
|
@type name: string
|
||||||
'''
|
'''
|
||||||
if iswindows:
|
if iswindows:
|
||||||
mutexname = 'mutexforsingleinstanceof'+__appname__+name
|
mutexname = 'mutexforsingleinstanceof'+__appname__+name
|
||||||
@ -82,5 +81,5 @@ def singleinstance(name):
|
|||||||
return True
|
return True
|
||||||
except IOError:
|
except IOError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user