def __init__(self, communicator=None, name='', lock=None, watched=None): self._intercom = communicator self._name = name or DEFAULT_BASENAME self._lock = lock or dummy_threading.Lock() self._watched = watched self.pool_size = 200 # 0) Clear counters self.joined_event_count = 0
## file. When replaying, a "checkpoint <comment>" line in the log ## file won't finish until the same checkpoint is reached by the ## executing code. There is no constraint on the order in which ## checkpoints are reached when running in threaded mode. import logutils import sys _checkpointdict = {} try: import threading _checkpointlock = threading.Lock() except ImportError: import dummy_threading _checkpointlock = dummy_threading.Lock() def checkpoint(comment): _checkpointlock.acquire() try: if logutils.recording(): # recording print >> logutils.logfile(), "checkpoint", comment logutils.logfile().flush() if logutils.debugLevel() >= 2: print >> sys.stderr, "////// checkpoint", comment if logutils.replaying(): try: _checkpointdict[comment] += 1 except KeyError: _checkpointdict[comment] = 1
#! usr/bin/env python # bad dummy_threading!!!! import dummy_threading as threading import time num = 0 lock = threading.Lock() def run(): time.sleep(1) lock.acquire() global num num += 1 lock.release() print('{}'.format(num)) for i in range(10): t = threading.Thread(target=run) t.start()
def update_event(self, inp=-1): self.set_output_val(0, dummy_threading.Lock())
from numpy.distutils import log from numpy.distutils.compat import get_exception from numpy.distutils.exec_command import (filepath_from_subprocess_output, forward_bytes_to_stdout) from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, \ get_num_build_jobs, \ _commandline_dep_string # globals for parallel build management try: import threads_new except ImportError: import dummy_threading as threading _job_semaphore = None _global_lock = threading.Lock() _processing_files = set() def _needs_build(obj, cc_args, extra_postargs, pp_opts): """ Check if an objects needs to be rebuild based on its dependencies Parameters ---------- obj : str object file Returns ------- bool
from moose.utils.module_loading import import_string from moose.conf import settings """ Provides an uniform interface with multithreading, but in a blocked way. The reason we provide the blocked worker is to offer a way to debug, espacially when using actions like `export`. """ if settings.DEBUG: import dummy_threading as _threading else: try: import threading as _threading except ImportError: import dummy_threading as _threading lock = _threading.Lock() import logging logger = logging.getLogger(__name__) class DownloadWorker(_threading.Thread): def __init__(self, queue, callback, stats, timeout, overwrite=False): super(DownloadWorker, self).__init__() self.queue = queue self.callback = callback # a mutex to count in threads self.stats = stats self.timeout = timeout self.overwrite = overwrite