mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Delay some imports
This commit is contained in:
parent
04f6473f38
commit
e90b79cf17
@ -8,9 +8,7 @@ __docformat__ = 'restructuredtext en'
|
||||
import errno
|
||||
import os
|
||||
|
||||
from calibre import force_unicode
|
||||
from calibre.constants import filesystem_encoding, get_windows_username, islinux, iswindows
|
||||
from calibre.utils.filenames import ascii_filename
|
||||
from polyglot.functools import lru_cache
|
||||
|
||||
VADDRESS = None
|
||||
@ -28,6 +26,8 @@ def eintr_retry_call(func, *args, **kwargs):
|
||||
|
||||
@lru_cache()
|
||||
def socket_address(which):
|
||||
from calibre import force_unicode
|
||||
from calibre.utils.filenames import ascii_filename
|
||||
if iswindows:
|
||||
ans = r'\\.\pipe\Calibre' + which
|
||||
try:
|
||||
|
@ -12,9 +12,8 @@ from contextlib import suppress
|
||||
from functools import wraps
|
||||
from threading import Lock
|
||||
|
||||
from calibre.constants import iswindows
|
||||
from calibre.utils.filenames import make_long_path_useable
|
||||
from calibre.utils.ipc.simple_worker import start_pipe_worker
|
||||
_plat = sys.platform.lower()
|
||||
iswindows = 'win32' in _plat or 'win64' in _plat
|
||||
|
||||
lock = Lock()
|
||||
worker = None
|
||||
@ -32,12 +31,12 @@ def thread_safe(f):
|
||||
|
||||
|
||||
@thread_safe
|
||||
def remove_folder(path: str) -> None:
|
||||
def remove_folder_atexit(path: str) -> None:
|
||||
_send_command(RMTREE_ACTION, os.path.abspath(path))
|
||||
|
||||
|
||||
@thread_safe
|
||||
def remove_file(path: str) -> None:
|
||||
def remove_file_atexit(path: str) -> None:
|
||||
_send_command(UNLINK_ACTION, os.path.abspath(path))
|
||||
|
||||
|
||||
@ -51,6 +50,7 @@ def unlink(path):
|
||||
def ensure_worker():
|
||||
global worker
|
||||
if worker is None:
|
||||
from calibre.utils.ipc.simple_worker import start_pipe_worker
|
||||
worker = start_pipe_worker('from calibre.utils.safe_atexit import main; main()', stdout=None)
|
||||
def close_worker():
|
||||
worker.stdin.close()
|
||||
@ -68,6 +68,7 @@ def _send_command(action: str, payload: str) -> None:
|
||||
|
||||
if iswindows:
|
||||
def remove_dir(x):
|
||||
from calibre.utils.filenames import make_long_path_useable
|
||||
x = make_long_path_useable(x)
|
||||
import shutil
|
||||
import time
|
||||
@ -107,7 +108,7 @@ def main_for_test(do_forced_exit=False):
|
||||
tf = 'test-folder'
|
||||
os.mkdir(tf)
|
||||
open(os.path.join(tf, 'test-file'), 'w').close()
|
||||
remove_folder(tf)
|
||||
remove_folder_atexit(tf)
|
||||
if do_forced_exit:
|
||||
os._exit(os.EX_OK)
|
||||
else:
|
||||
@ -118,6 +119,8 @@ def find_tests():
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from calibre.utils.ipc.simple_worker import start_pipe_worker
|
||||
|
||||
class TestSafeAtexit(unittest.TestCase):
|
||||
|
||||
def wait_for_empty(self, tdir, timeout=10):
|
||||
|
Loading…
x
Reference in New Issue
Block a user