本文整理汇总了Python中os.nice方法的典型用法代码示例。如果您正苦于以下问题:Python os.nice方法的具体用法?Python os.nice怎么用?Python os.nice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.nice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_popen_nice
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def test_popen_nice(self, makegateway):
gw = makegateway("popen")
def getnice(channel):
import os
if hasattr(os, "nice"):
channel.send(os.nice(0))
else:
channel.send(None)
remotenice = gw.remote_exec(getnice).receive()
gw.exit()
if remotenice is not None:
gw = makegateway("popen//nice=5")
remotenice2 = gw.remote_exec(getnice).receive()
assert remotenice2 == remotenice + 5
示例2: run
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def run(self):
""" Main processing loop. """
# Try setting the process niceness (available only on Unix systems)
try:
os.nice(20)
print('Set low priority for the LiveViewer thread!')
except Exception as e:
print('Setting niceness failed with message:\n' + repr(e))
if self.slideshow:
self.startSlideshow()
else:
self.monitorDir()
示例3: spawnAll
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def spawnAll(self, niceness, show_output = 0):
"""
Spawn many jobs.
@param niceness: nice dictionary [host-name: niceness]
@type niceness: dict
"""
self.slaves = {}
for d in self.hosts:
host = d['host']
nickname = d['nickname']
try:
nice = niceness[host]
except:
nice = niceness.get('default', 0)
slave_tid = self.spawn(host, nickname, nice, show_output)
if slave_tid <= 0:
print 'error spawning', host
try:
print '\t', pvm.pvmerrors[ slave_tid ]
except Exception, error:
print 'unknown error', error
else:
self.bindMessages(slave_tid)
self.slaves[slave_tid] = d
if self.verbose: print slave_tid, nickname, 'spawned.'
示例4: _child
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def _child(self, nice_level, child_on_start, child_on_exit):
# right now we need to call a function, but first we need to
# map all IO that might happen
sys.stdout = stdout = get_unbuffered_io(1, self.STDOUT)
sys.stderr = stderr = get_unbuffered_io(2, self.STDERR)
retvalf = self.RETVAL.open("wb")
EXITSTATUS = 0
try:
if nice_level:
os.nice(nice_level)
try:
if child_on_start is not None:
child_on_start()
retval = self.fun(*self.args, **self.kwargs)
retvalf.write(marshal.dumps(retval))
if child_on_exit is not None:
child_on_exit()
except:
excinfo = py.code.ExceptionInfo()
stderr.write(str(excinfo._getreprcrash()))
EXITSTATUS = self.EXITSTATUS_EXCEPTION
finally:
stdout.close()
stderr.close()
retvalf.close()
os.close(1)
os.close(2)
os._exit(EXITSTATUS)
示例5: _run_wrapper
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def _run_wrapper(conn: 'multiprocessing.connection.Connection', priority: int, runner: Callable, args: Sequence[Any]) -> None:
start_time = time.time()
os.nice(priority)
try:
result = runner(*args) if args else runner()
conn.send((State.DONE, time.time() - start_time, result))
except Exception as exc:
conn.send((State.FAILED, time.time() - start_time, exc))
finally:
conn.close()
示例6: run
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def run(self, *runner_args: Any, **kwargs: Any) -> None:
def _wrapper(conn: 'multiprocessing.connection.Connection', runner: Callable, args: Any) -> None:
os.nice(12)
try:
runner(*args) if args else runner()
conn.send(AsyncResult('success', None))
except AssertionError as exc:
conn.send(AsyncResult('failure', str(exc)))
except unittest.case.SkipTest as exc:
conn.send(AsyncResult('skipped', str(exc)))
except:
conn.send(AsyncResult('error', traceback.format_exc()))
finally:
conn.close()
with self._process_lock:
if self._status == AsyncStatus.PENDING:
if runner_args:
self._runner_args = runner_args
if 'threaded' in kwargs:
self._threaded = kwargs['threaded']
self._process_pipe, child_pipe = multiprocessing.Pipe()
if self._threaded:
self._process = threading.Thread(
target = _wrapper,
args = (child_pipe, self._runner, self._runner_args),
name = 'Background test of %s' % self.name,
)
self._process.setDaemon(True)
else:
self._process = multiprocessing.Process(target = _wrapper, args = (child_pipe, self._runner, self._runner_args))
self._process.start()
self._status = AsyncStatus.RUNNING
示例7: _run_chassis
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def _run_chassis(fabricconfig, mgmtbusconfig, fts):
try:
# lower priority to make master and web
# more "responsive"
os.nice(5)
c = minemeld.chassis.Chassis(
fabricconfig['class'],
fabricconfig['config'],
mgmtbusconfig
)
c.configure(fts)
gevent.signal(signal.SIGUSR1, c.stop)
while not c.fts_init():
if c.poweroff.wait(timeout=0.1) is not None:
break
gevent.sleep(1)
LOG.info('Nodes initialized')
try:
c.poweroff.wait()
LOG.info('power off')
except KeyboardInterrupt:
LOG.error("We should not be here !")
c.stop()
except:
LOG.exception('Exception in chassis main procedure')
raise
示例8: sysmetrics_loop
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def sysmetrics_loop(self):
try:
os.nice(-19)
self.info("Logging system metrics with superior process priority.")
except:
self.info("Logging system metrics without superior process priority.")
while True:
metrics = self.sysmetrics_update()
self.sysmetrics2tboard(metrics, global_step=metrics["rel_time"])
# print("thread alive", self.thread.is_alive())
time.sleep(self.sysmetrics_interval)
示例9: run
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def run(self):
print("STARTING IMPROVEMENT JOB {}".format(self.q.name))
os.makedirs(log_dir.value, exist_ok=True)
with open(os.path.join(log_dir.value, "{}.log".format(self.q.name)), "w", buffering=LINE_BUFFER_MODE) as f:
sys.stdout = f
print("STARTING IMPROVEMENT JOB {}".format(self.q.name))
print(pprint(self.q))
if nice_children.value:
os.nice(20)
cost_model = CostModel(
funcs=self.context.funcs(),
assumptions=EAll(self.assumptions),
freebies=self.freebies,
ops=self.ops)
try:
for expr in itertools.chain((self.q.ret,), core.improve(
target=self.q.ret,
assumptions=EAll(self.assumptions),
context=self.context,
hints=self.hints,
stop_callback=lambda: self.stop_requested,
cost_model=cost_model,
ops=self.ops,
improve_count=self.improve_count)):
new_rep, new_ret = unpack_representation(expr)
self.k(new_rep, new_ret)
print("PROVED OPTIMALITY FOR {}".format(self.q.name))
except core.StopException:
print("stopping synthesis of {}".format(self.q.name))
return
示例10: test_norm_attributes
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def test_norm_attributes(self):
spec = XSpec(
r"socket=192.168.102.2:8888//python=c:/this/python2.5" r"//chdir=d:\hello"
)
assert spec.socket == "192.168.102.2:8888"
assert spec.python == "c:/this/python2.5"
assert spec.chdir == r"d:\hello"
assert spec.nice is None
assert not hasattr(spec, "_xyz")
with pytest.raises(AttributeError):
spec._hello()
spec = XSpec("socket=192.168.102.2:8888//python=python2.5//nice=3")
assert spec.socket == "192.168.102.2:8888"
assert spec.python == "python2.5"
assert spec.chdir is None
assert spec.nice == "3"
spec = XSpec("ssh=user@host" "//chdir=/hello/this//python=/usr/bin/python2.5")
assert spec.ssh == "user@host"
assert spec.python == "/usr/bin/python2.5"
assert spec.chdir == "/hello/this"
spec = XSpec("popen")
assert spec.popen is True
示例11: pool_worker_main
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def pool_worker_main(item: WorkItemInput, output: multiprocessing.queues.Queue) -> None:
try:
# TODO figure out a more reliable way to suppress this. Redirect output?
# Ignore ctrl-c in workers to reduce noisy tracebacks (the parent will kill us):
signal.signal(signal.SIGINT, signal.SIG_IGN)
if hasattr(os, 'nice'): # analysis should run at a low priority
os.nice(10)
set_debug(False)
filename, options, deadline = item
stats: Counter[str] = Counter()
options.stats = stats
_, module_name = extract_module_from_file(filename)
try:
module = load_by_qualname(module_name)
except NotFound:
return
except ErrorDuringImport as e:
output.put((filename, stats, [import_error_msg(e)]))
debug(f'Not analyzing "{filename}" because import failed: {e}')
return
messages = analyze_any(module, options)
output.put((filename, stats, messages))
except BaseException as e:
raise CrosshairInternal(
'Worker failed while analyzing ' + filename) from e
示例12: nice
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def nice(level):
pass
示例13: beNice
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def beNice(very_nice=False):
if very_nice:
value = 10
else:
value = 5
nice(value)
示例14: main
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def main():
"""Start the main app executable in the hosting OS environment."""
env_work_dir = ambianic.get_work_dir()
ambianic.server_instance = ambianic.server.AmbianicServer(
work_dir=env_work_dir
)
# run with a little lower priority
# to avoid delaying docker container from syncing with OS resources
# such as log files
os.nice(1)
# start main server
ambianic.server_instance.start()
示例15: start_gst_service
# 需要导入模块: import os [as 别名]
# 或者: from os import nice [as 别名]
def start_gst_service(source_conf=None,
out_queue=None,
stop_signal=None,
eos_reached=None):
svc = GstService(source_conf=source_conf,
out_queue=out_queue,
stop_signal=stop_signal,
eos_reached=eos_reached)
# set priority level below parent process
# in order to preserve UX responsiveness
os.nice(10)
svc.run()
log.info('Exiting GST process')