mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DRYer
This commit is contained in:
parent
7efc361602
commit
cd93465871
@ -75,6 +75,14 @@ def headless_exe_path(exe_name='calibre-parallel'):
|
|||||||
return exe_path(exe_name)
|
return exe_path(exe_name)
|
||||||
|
|
||||||
|
|
||||||
|
def windows_creationflags_for_worker_process(priority: str = 'normal') -> int:
|
||||||
|
return {
|
||||||
|
'high' : subprocess.HIGH_PRIORITY_CLASS,
|
||||||
|
'normal': subprocess.NORMAL_PRIORITY_CLASS,
|
||||||
|
'low' : subprocess.IDLE_PRIORITY_CLASS
|
||||||
|
}[priority] | subprocess.CREATE_NO_WINDOW
|
||||||
|
|
||||||
|
|
||||||
class Worker:
|
class Worker:
|
||||||
'''
|
'''
|
||||||
Platform independent object for launching child processes. All processes
|
Platform independent object for launching child processes. All processes
|
||||||
@ -182,11 +190,7 @@ class Worker:
|
|||||||
'cwd': _cwd,
|
'cwd': _cwd,
|
||||||
}
|
}
|
||||||
if iswindows:
|
if iswindows:
|
||||||
priority = {
|
args['creationflags'] = windows_creationflags_for_worker_process(priority)
|
||||||
'high' : subprocess.HIGH_PRIORITY_CLASS,
|
|
||||||
'normal': subprocess.NORMAL_PRIORITY_CLASS,
|
|
||||||
'low' : subprocess.IDLE_PRIORITY_CLASS}[priority]
|
|
||||||
args['creationflags'] = subprocess.CREATE_NO_WINDOW|priority
|
|
||||||
else:
|
else:
|
||||||
niceness = {
|
niceness = {
|
||||||
'normal': 0,
|
'normal': 0,
|
||||||
|
@ -14,7 +14,7 @@ from threading import Thread
|
|||||||
|
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre.utils.ipc import eintr_retry_call
|
from calibre.utils.ipc import eintr_retry_call
|
||||||
from calibre.utils.ipc.launch import Worker
|
from calibre.utils.ipc.launch import Worker, windows_creationflags_for_worker_process
|
||||||
from calibre.utils.monotonic import monotonic
|
from calibre.utils.monotonic import monotonic
|
||||||
from polyglot.builtins import environ_item, string_or_bytes
|
from polyglot.builtins import environ_item, string_or_bytes
|
||||||
|
|
||||||
@ -142,11 +142,7 @@ def start_pipe_worker(command, env=None, priority='normal', **process_args):
|
|||||||
pass_fds = None
|
pass_fds = None
|
||||||
try:
|
try:
|
||||||
if iswindows:
|
if iswindows:
|
||||||
priority = {
|
args['creationflags'] = windows_creationflags_for_worker_process(priority)
|
||||||
'high' : subprocess.HIGH_PRIORITY_CLASS,
|
|
||||||
'normal': subprocess.NORMAL_PRIORITY_CLASS,
|
|
||||||
'low' : subprocess.IDLE_PRIORITY_CLASS}[priority]
|
|
||||||
args['creationflags'] = subprocess.CREATE_NO_WINDOW|priority
|
|
||||||
pass_fds = args.pop('pass_fds', None)
|
pass_fds = args.pop('pass_fds', None)
|
||||||
if pass_fds:
|
if pass_fds:
|
||||||
for fd in pass_fds:
|
for fd in pass_fds:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user