mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Better error message when startup fails because of singleinstance failing
This commit is contained in:
parent
99b8a76b00
commit
6703980121
@ -378,8 +378,11 @@ def run_gui(opts, args, listener, app, gui_debug=None):
|
|||||||
open_local_file(debugfile)
|
open_local_file(debugfile)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
singleinstance_name = 'calibre_GUI'
|
||||||
|
|
||||||
def cant_start(msg=_('If you are sure it is not running')+', ',
|
def cant_start(msg=_('If you are sure it is not running')+', ',
|
||||||
det_msg=_('Timed out waiting for response from running calibre')):
|
det_msg=_('Timed out waiting for response from running calibre'),
|
||||||
|
listener_failed=False):
|
||||||
base = '<p>%s</p><p>%s %s'
|
base = '<p>%s</p><p>%s %s'
|
||||||
where = __appname__ + ' '+_('may be running in the system tray, in the')+' '
|
where = __appname__ + ' '+_('may be running in the system tray, in the')+' '
|
||||||
if isosx:
|
if isosx:
|
||||||
@ -388,8 +391,17 @@ def cant_start(msg=_('If you are sure it is not running')+', ',
|
|||||||
where += _('lower right region of the screen.')
|
where += _('lower right region of the screen.')
|
||||||
if iswindows or islinux:
|
if iswindows or islinux:
|
||||||
what = _('try rebooting your computer.')
|
what = _('try rebooting your computer.')
|
||||||
|
if islinux and not listener_failed:
|
||||||
|
from calibre.utils.lock import singleinstance_path
|
||||||
|
path = singleinstance_path(singleinstance_name)
|
||||||
|
what = _('try deleting the file: "%s"') % path
|
||||||
else:
|
else:
|
||||||
what = _('try deleting the file')+': '+ gui_socket_address()
|
if listener_failed:
|
||||||
|
path = gui_socket_address()
|
||||||
|
else:
|
||||||
|
from calibre.utils.lock import singleinstance_path
|
||||||
|
path = singleinstance_path(singleinstance_name)
|
||||||
|
what = _('try deleting the file: "%s"') % path
|
||||||
|
|
||||||
info = base%(where, msg, what)
|
info = base%(where, msg, what)
|
||||||
error_dialog(None, _('Cannot Start ')+__appname__,
|
error_dialog(None, _('Cannot Start ')+__appname__,
|
||||||
@ -416,7 +428,7 @@ def shutdown_other(rc=None):
|
|||||||
rc.conn.send('shutdown:')
|
rc.conn.send('shutdown:')
|
||||||
prints(_('Shutdown command sent, waiting for shutdown...'))
|
prints(_('Shutdown command sent, waiting for shutdown...'))
|
||||||
for i in xrange(50):
|
for i in xrange(50):
|
||||||
if singleinstance('calibre GUI'):
|
if singleinstance(singleinstance_name):
|
||||||
return
|
return
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
prints(_('Failed to shutdown running calibre instance'))
|
prints(_('Failed to shutdown running calibre instance'))
|
||||||
@ -460,13 +472,13 @@ def main(args=sys.argv):
|
|||||||
listener = create_listener()
|
listener = create_listener()
|
||||||
except socket.error:
|
except socket.error:
|
||||||
if iswindows or islinux:
|
if iswindows or islinux:
|
||||||
cant_start(det_msg=traceback.format_exc())
|
cant_start(det_msg=traceback.format_exc(), listener_failed=True)
|
||||||
if os.path.exists(gui_socket_address()):
|
if os.path.exists(gui_socket_address()):
|
||||||
os.remove(gui_socket_address())
|
os.remove(gui_socket_address())
|
||||||
try:
|
try:
|
||||||
listener = create_listener()
|
listener = create_listener()
|
||||||
except socket.error:
|
except socket.error:
|
||||||
cant_start(det_msg=traceback.format_exc())
|
cant_start(det_msg=traceback.format_exc(), listener_failed=True)
|
||||||
else:
|
else:
|
||||||
return run_gui(opts, args, listener, app,
|
return run_gui(opts, args, listener, app,
|
||||||
gui_debug=gui_debug)
|
gui_debug=gui_debug)
|
||||||
|
@ -191,6 +191,8 @@ def _clean_lock_file(file):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def singleinstance_path(name):
|
||||||
|
return os.path.expanduser('~/.'+__appname__+'_'+name+'.lock')
|
||||||
|
|
||||||
def singleinstance(name):
|
def singleinstance(name):
|
||||||
'''
|
'''
|
||||||
@ -211,7 +213,7 @@ def singleinstance(name):
|
|||||||
atexit.register(win32api.CloseHandle, mutex)
|
atexit.register(win32api.CloseHandle, mutex)
|
||||||
return not err == winerror.ERROR_ALREADY_EXISTS
|
return not err == winerror.ERROR_ALREADY_EXISTS
|
||||||
else:
|
else:
|
||||||
path = os.path.expanduser('~/.'+__appname__+'_'+name+'.lock')
|
path = singleinstance_path(name)
|
||||||
try:
|
try:
|
||||||
f = open(path, 'w')
|
f = open(path, 'w')
|
||||||
fcntl.lockf(f.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
fcntl.lockf(f.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user