mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Make singleinstance() more robust on OS X
It now handles EINTR and also does not hide all errors in opening the file or calling lockf() An error is now reported to the user in a nice error dialog before aborting startup.
This commit is contained in:
parent
e486e67d57
commit
f8aea31f40
@ -459,8 +459,14 @@ def main(args=sys.argv):
|
||||
app, opts, args = init_qt(args)
|
||||
except AbortInit:
|
||||
return 1
|
||||
try:
|
||||
from calibre.utils.lock import singleinstance
|
||||
si = singleinstance(singleinstance_name)
|
||||
except Exception:
|
||||
error_dialog(None, _('Cannot start calibre'), _(
|
||||
'Failed to start calibre, single instance locking failed. Click "Show Details" for more information'),
|
||||
det_msg=traceback.format_exc(), show=True)
|
||||
return 1
|
||||
if si and opts.shutdown_running_calibre:
|
||||
return 0
|
||||
if si:
|
||||
|
@ -233,12 +233,15 @@ else:
|
||||
@param name: The name to lock.
|
||||
@type name: string
|
||||
'''
|
||||
from calibre.utils.ipc import eintr_retry_call
|
||||
path = singleinstance_path(name)
|
||||
try:
|
||||
f = open(path, 'w')
|
||||
fcntl.lockf(f.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||
try:
|
||||
eintr_retry_call(fcntl.lockf, f.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||
atexit.register(_clean_lock_file, f)
|
||||
return True
|
||||
except EnvironmentError:
|
||||
pass
|
||||
except IOError as err:
|
||||
if err.errno == errno.EAGAIN:
|
||||
return False
|
||||
raise
|
||||
return False
|
||||
|
Loading…
x
Reference in New Issue
Block a user