mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Fix calibre-server not exiting on ctrl+c on Windows
This commit is contained in:
parent
2d4c770d3d
commit
b8e69e1bc1
@ -763,7 +763,12 @@ class EchoLine(Connection): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def main():
|
||||||
|
print('Starting Echo server')
|
||||||
s = ServerLoop(EchoLine)
|
s = ServerLoop(EchoLine)
|
||||||
with HandleInterrupt(s.wakeup):
|
with HandleInterrupt(s.stop):
|
||||||
s.serve_forever()
|
s.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
@ -20,7 +20,7 @@ from calibre.srv.loop import BadIPSpec, ServerLoop
|
|||||||
from calibre.srv.manage_users_cli import manage_users_cli
|
from calibre.srv.manage_users_cli import manage_users_cli
|
||||||
from calibre.srv.opts import opts_to_parser
|
from calibre.srv.opts import opts_to_parser
|
||||||
from calibre.srv.users import connect
|
from calibre.srv.users import connect
|
||||||
from calibre.srv.utils import RotatingLog
|
from calibre.srv.utils import HandleInterrupt, RotatingLog
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.utils.localization import localize_user_manual_link
|
from calibre.utils.localization import localize_user_manual_link
|
||||||
from calibre.utils.lock import singleinstance
|
from calibre.utils.lock import singleinstance
|
||||||
@ -188,7 +188,7 @@ def main(args=sys.argv):
|
|||||||
if getattr(opts, 'daemonize', False):
|
if getattr(opts, 'daemonize', False):
|
||||||
raise SystemExit(
|
raise SystemExit(
|
||||||
'Cannot specify --auto-reload and --daemonize at the same time')
|
'Cannot specify --auto-reload and --daemonize at the same time')
|
||||||
from calibre.srv.auto_reload import auto_reload, NoAutoReload
|
from calibre.srv.auto_reload import NoAutoReload, auto_reload
|
||||||
try:
|
try:
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
return auto_reload(default_log, listen_on=opts.listen_on)
|
return auto_reload(default_log, listen_on=opts.listen_on)
|
||||||
@ -241,6 +241,7 @@ def main(args=sys.argv):
|
|||||||
# Needed for dynamic cover generation, which uses Qt for drawing
|
# Needed for dynamic cover generation, which uses Qt for drawing
|
||||||
from calibre.gui2 import ensure_app, load_builtin_fonts
|
from calibre.gui2 import ensure_app, load_builtin_fonts
|
||||||
ensure_app(), load_builtin_fonts()
|
ensure_app(), load_builtin_fonts()
|
||||||
|
with HandleInterrupt(server.stop):
|
||||||
try:
|
try:
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
finally:
|
finally:
|
||||||
|
@ -391,7 +391,7 @@ class HandleInterrupt(object): # {{{
|
|||||||
# On windows socket functions like accept(), recv(), send() are not
|
# On windows socket functions like accept(), recv(), send() are not
|
||||||
# interrupted by a Ctrl-C in the console. So to make Ctrl-C work we have to
|
# interrupted by a Ctrl-C in the console. So to make Ctrl-C work we have to
|
||||||
# use this special context manager. See the echo server example at the
|
# use this special context manager. See the echo server example at the
|
||||||
# bottom of this file for how to use it.
|
# bottom of srv/loop.py for how to use it.
|
||||||
|
|
||||||
def __init__(self, action):
|
def __init__(self, action):
|
||||||
if not iswindows:
|
if not iswindows:
|
||||||
@ -414,12 +414,7 @@ class HandleInterrupt(object): # {{{
|
|||||||
if self.action is not None:
|
if self.action is not None:
|
||||||
self.action()
|
self.action()
|
||||||
self.action = None
|
self.action = None
|
||||||
# Typical C implementations would return 1 to indicate that
|
return 1
|
||||||
# the event was processed and other control handlers in the
|
|
||||||
# stack should not be executed. However, that would
|
|
||||||
# prevent the Python interpreter's handler from translating
|
|
||||||
# CTRL-C to a `KeyboardInterrupt` exception, so we pretend
|
|
||||||
# that we didn't handle it.
|
|
||||||
return 0
|
return 0
|
||||||
self.handle = handle
|
self.handle = handle
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user