mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More robust atexit worker close
This commit is contained in:
parent
2ccec1c8e2
commit
2ebf2af44f
@ -47,15 +47,22 @@ def unlink(path):
|
|||||||
oss.remove(path)
|
oss.remove(path)
|
||||||
|
|
||||||
|
|
||||||
|
def close_worker(worker):
|
||||||
|
import subprocess
|
||||||
|
worker.stdin.close()
|
||||||
|
try:
|
||||||
|
worker.wait(10)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
worker.kill()
|
||||||
|
worker.wait()
|
||||||
|
|
||||||
|
|
||||||
def ensure_worker():
|
def ensure_worker():
|
||||||
global worker
|
global worker
|
||||||
if worker is None:
|
if worker is None:
|
||||||
from calibre.utils.ipc.simple_worker import start_pipe_worker
|
from calibre.utils.ipc.simple_worker import start_pipe_worker
|
||||||
worker = start_pipe_worker('from calibre.utils.safe_atexit import main; main()', stdout=None)
|
worker = start_pipe_worker('from calibre.utils.safe_atexit import main; main()', stdout=None)
|
||||||
def close_worker():
|
atexit.register(close_worker, worker)
|
||||||
worker.stdin.close()
|
|
||||||
worker.wait(10)
|
|
||||||
atexit.register(close_worker)
|
|
||||||
return worker
|
return worker
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user