mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
OSX and Linux: Add a setting in Preferences->Behavior to control the priority with which calibre worker processes run. Fixes #741231 (calibre-parallel process priority)
This commit is contained in:
parent
90a53c6dcf
commit
468ac27782
@ -31,9 +31,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
db = gui.library_view.model().db
|
||||
|
||||
r = self.register
|
||||
|
||||
r('worker_process_priority', prefs, choices=
|
||||
[(_('Low'), 'low'), (_('Normal'), 'normal'), (_('High'), 'high')])
|
||||
choices = [(_('Low'), 'low'), (_('Normal'), 'normal'), (_('High'),
|
||||
'high')] if iswindows else \
|
||||
[(_('Normal'), 'normal'), (_('Low'), 'low'), (_('Very low'),
|
||||
'high')]
|
||||
r('worker_process_priority', prefs, choices=choices)
|
||||
|
||||
r('network_timeout', prefs)
|
||||
|
||||
@ -60,9 +62,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
signal = getattr(self.opt_internally_viewed_formats, 'item'+signal)
|
||||
signal.connect(self.internally_viewed_formats_changed)
|
||||
|
||||
self.settings['worker_process_priority'].gui_obj.setVisible(iswindows)
|
||||
self.priority_label.setVisible(iswindows)
|
||||
|
||||
|
||||
def initialize(self):
|
||||
ConfigWidgetBase.initialize(self)
|
||||
|
@ -7,6 +7,7 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
import subprocess, os, sys, time, binascii, cPickle
|
||||
from functools import partial
|
||||
|
||||
from calibre.constants import iswindows, isosx, isfrozen
|
||||
from calibre.utils.config import prefs
|
||||
@ -19,6 +20,12 @@ if iswindows:
|
||||
except:
|
||||
raise RuntimeError('NUL %r file missing in windows'%os.devnull)
|
||||
|
||||
def renice(niceness):
|
||||
try:
|
||||
os.nice(niceness)
|
||||
except:
|
||||
pass
|
||||
|
||||
class Worker(object):
|
||||
'''
|
||||
Platform independent object for launching child processes. All processes
|
||||
@ -144,6 +151,13 @@ class Worker(object):
|
||||
'normal' : win32process.NORMAL_PRIORITY_CLASS,
|
||||
'low' : win32process.IDLE_PRIORITY_CLASS}[priority]
|
||||
args['creationflags'] = win32process.CREATE_NO_WINDOW|priority
|
||||
else:
|
||||
niceness = {
|
||||
'normal' : 0,
|
||||
'low' : 10,
|
||||
'high' : 20,
|
||||
}[priority]
|
||||
args['preexec_fn'] = partial(renice, niceness)
|
||||
ret = None
|
||||
if redirect_output:
|
||||
self._file = PersistentTemporaryFile('_worker_redirect.log')
|
||||
|
Loading…
x
Reference in New Issue
Block a user