From 928850c2a852b5f4e4c49df9e6505cf9177a4f25 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Tue, 11 Jul 2017 12:44:26 +0000 Subject: [PATCH] lower process priority --- onn.py | 1 + onn_core.py | 18 ++++++++++++++++++ onn_mnist.py | 1 + 3 files changed, 20 insertions(+) diff --git a/onn.py b/onn.py index 6d8ea04..fa718c1 100755 --- a/onn.py +++ b/onn.py @@ -991,6 +991,7 @@ def model_from_config(config, input_features, output_features, callbacks): def run(program, args=None): args = args if args else [] + lower_priority() np.random.seed(42069) # Config {{{2 diff --git a/onn_core.py b/onn_core.py index 4c82ef8..c77e3a6 100644 --- a/onn_core.py +++ b/onn_core.py @@ -4,6 +4,24 @@ import types def lament(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) +def lower_priority(): + """Set the priority of the process to below-normal.""" + # via https://stackoverflow.com/a/1023269 + if sys.platform == 'win32': + try: + import win32api, win32process, win32con + pid = win32api.GetCurrentProcessId() + handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid) + win32process.SetPriorityClass(handle, win32process.BELOW_NORMAL_PRIORITY_CLASS) + except ImportError: + lament("you do not have pywin32 installed.") + lament("the process priority could not be lowered.") + lament("consider: python -m pip install pypiwin32") + lament("consider: conda install pywin32") + else: + import os + os.nice(1) + import numpy as np _f = np.float32 diff --git a/onn_mnist.py b/onn_mnist.py index 8aa8afc..0e8e296 100755 --- a/onn_mnist.py +++ b/onn_mnist.py @@ -4,6 +4,7 @@ from onn import * from onn_core import _f from dotmap import DotMap +lower_priority() #np.random.seed(42069) use_emnist = True