def test_num_threads_variable(self): """ Tests the NUMBA_NUM_THREADS env variable behaves as expected. """ key = 'NUMBA_NUM_THREADS' current = str(getattr(env, key, config.NUMBA_DEFAULT_NUM_THREADS)) threads = "3154" env[key] = threads config.reload_config() try: self.assertEqual(threads, str(get_thread_count())) self.assertEqual(threads, str(config.NUMBA_NUM_THREADS)) finally: # reset the env variable/set to default env[key] = current config.reload_config()
def override_env_config(name, value): """ Return a context manager that temporarily sets an Numba config environment *name* to *value*. """ old = os.environ.get(name) os.environ[name] = value config.reload_config() try: yield finally: if old is None: # If it wasn't set originally, delete the environ var del os.environ[name] else: # Otherwise, restore to the old value os.environ[name] = old # Always reload config config.reload_config()
def test_num_threads_variable(self): """ Tests the NUMBA_NUM_THREADS env variable behaves as expected. """ key = 'NUMBA_NUM_THREADS' current = str(getattr(env, key, config.NUMBA_NUM_THREADS)) threads = "3154" env[key] = threads try: config.reload_config() except RuntimeError as e: # This test should fail if threads have already been launched self.assertIn("Cannot set NUMBA_NUM_THREADS", e.args[0]) else: self.assertEqual(threads, str(get_thread_count())) self.assertEqual(threads, str(config.NUMBA_NUM_THREADS)) finally: # reset the env variable/set to default. Should not fail even if # threads are launched because the value is the same. env[key] = current config.reload_config()
def __init__(self, typingctx, targetctx, library, args, return_type, flags, locals): # Make sure the environment is reloaded config.reload_config() typingctx.refresh() targetctx.refresh() self.state = StateDict() self.state.typingctx = typingctx self.state.targetctx = _make_subtarget(targetctx, flags) self.state.library = library self.state.args = args self.state.return_type = return_type self.state.flags = flags self.state.locals = locals # Results of various steps of the compilation pipeline self.state.bc = None self.state.func_id = None self.state.func_ir = None self.state.lifted = None self.state.lifted_from = None self.state.typemap = None self.state.calltypes = None self.state.type_annotation = None # holds arbitrary inter-pipeline stage meta data self.state.metadata = {} self.state.reload_init = [] # hold this for e.g. with_lifting, null out on exit self.state.pipeline = self # parfor diagnostics info, add to metadata self.state.parfor_diagnostics = ParforDiagnostics() self.state.metadata['parfor_diagnostics'] = \ self.state.parfor_diagnostics self.state.status = _CompileStatus( can_fallback=self.state.flags.enable_pyobject, can_giveup=config.COMPATIBILITY_MODE)