Fix unnecessary error when shutting down GUI IPC socket on linux

This commit is contained in:
Kovid Goyal 2014-03-28 10:02:31 +05:30
parent 3469076d03
commit a1d2bc80f9
3 changed files with 17 additions and 5 deletions

View File

@ -417,6 +417,15 @@ def communicate(opts, args):
t.conn.close() t.conn.close()
raise SystemExit(0) raise SystemExit(0)
def create_listener():
from multiprocessing.connection import Listener
listener = Listener(address=gui_socket_address())
if islinux and hasattr(listener._listener._unlink, 'cancel'):
# multiprocessing tries to call unlink even on abstract
# named sockets, prevent it from doing so.
listener._listener._unlink.cancel()
return listener
def main(args=sys.argv): def main(args=sys.argv):
gui_debug = None gui_debug = None
if args[0] == '__CALIBRE_GUI_DEBUG__': if args[0] == '__CALIBRE_GUI_DEBUG__':
@ -428,20 +437,19 @@ def main(args=sys.argv):
except AbortInit: except AbortInit:
return 1 return 1
from calibre.utils.lock import singleinstance from calibre.utils.lock import singleinstance
from multiprocessing.connection import Listener
si = singleinstance('calibre GUI') si = singleinstance('calibre GUI')
if si and opts.shutdown_running_calibre: if si and opts.shutdown_running_calibre:
return 0 return 0
if si: if si:
try: try:
listener = Listener(address=gui_socket_address()) listener = create_listener()
except socket.error: except socket.error:
if iswindows or islinux: if iswindows or islinux:
cant_start() cant_start()
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 = Listener(address=gui_socket_address()) listener = create_listener()
except socket.error: except socket.error:
cant_start() cant_start()
else: else:
@ -452,7 +460,7 @@ def main(args=sys.argv):
gui_debug=gui_debug) gui_debug=gui_debug)
otherinstance = False otherinstance = False
try: try:
listener = Listener(address=gui_socket_address()) listener = create_listener()
except socket.error: # Good si is correct (on UNIX) except socket.error: # Good si is correct (on UNIX)
otherinstance = True otherinstance = True
else: else:

View File

@ -72,7 +72,8 @@ class Listener(Thread): # {{{
try: try:
self.listener.close() self.listener.close()
except: except:
pass import traceback
traceback.print_exc()
# }}} # }}}

View File

@ -307,6 +307,9 @@ class Server(Thread):
def close(self): def close(self):
try: try:
self.add_jobs_queue.put(None) self.add_jobs_queue.put(None)
except:
pass
try:
self.listener.close() self.listener.close()
except: except:
pass pass