mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove unnecessary use of lock
This commit is contained in:
parent
d0f617307f
commit
9eb13264aa
@ -14,9 +14,10 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
from itertools import count
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from multiprocessing.connection import Listener, arbitrary_address
|
from multiprocessing.connection import Listener, arbitrary_address
|
||||||
from threading import RLock, Thread
|
from threading import Thread
|
||||||
|
|
||||||
from calibre import detect_ncpus as cpu_count, force_unicode
|
from calibre import detect_ncpus as cpu_count, force_unicode
|
||||||
from calibre.constants import DEBUG, cache_dir, islinux, iswindows
|
from calibre.constants import DEBUG, cache_dir, islinux, iswindows
|
||||||
@ -206,16 +207,13 @@ class Server(Thread):
|
|||||||
self.kill_queue = Queue()
|
self.kill_queue = Queue()
|
||||||
self.waiting_jobs = []
|
self.waiting_jobs = []
|
||||||
self.workers = deque()
|
self.workers = deque()
|
||||||
self.launched_worker_count = 0
|
self.launched_worker_counter = count()
|
||||||
self._worker_launch_lock = RLock()
|
next(self.launched_worker_counter)
|
||||||
|
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def launch_worker(self, gui=False, redirect_output=None, job_name=None):
|
def launch_worker(self, gui=False, redirect_output=None, job_name=None):
|
||||||
start = time.monotonic()
|
start = time.monotonic()
|
||||||
with self._worker_launch_lock:
|
id = next(self.launched_worker_counter)
|
||||||
self.launched_worker_count += 1
|
|
||||||
id = self.launched_worker_count
|
|
||||||
fd, rfile = tempfile.mkstemp(prefix='ipc_result_%d_%d_'%(self.id, id),
|
fd, rfile = tempfile.mkstemp(prefix='ipc_result_%d_%d_'%(self.id, id),
|
||||||
dir=base_dir(), suffix='.pickle')
|
dir=base_dir(), suffix='.pickle')
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
@ -231,7 +229,7 @@ class Server(Thread):
|
|||||||
if isinstance(cw, string_or_bytes):
|
if isinstance(cw, string_or_bytes):
|
||||||
raise CriticalError('Failed to launch worker process:\n'+force_unicode(cw))
|
raise CriticalError('Failed to launch worker process:\n'+force_unicode(cw))
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print('Worker Launch took:', time.monotonic() - start)
|
print('Worker Launch took: {:.2f} seconds'.format(time.monotonic() - start))
|
||||||
return cw
|
return cw
|
||||||
|
|
||||||
def do_launch(self, env, gui, redirect_output, rfile, job_name=None):
|
def do_launch(self, env, gui, redirect_output, rfile, job_name=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user