def __init__(self, ident): self.id = ident if ident != -1: self.name = "Unknown Thread " + text_type(ident) self.child_lock = allocate_lock() self.children = [] self.cprofiler = None
def __init__(self, ident): self.id = ident if ident != -1: self.name = "Unknown Thread " + text_type(ident) self.child_lock = allocate_lock() self.children = [] self.cprofiler = None
def __init__(self): BaseThread.__init__(self, get_ident()) self.name = "Main Thread" self.please_stop = Signal() self.stopped = Signal() self.stop_logging = Log.stop self.timers = None self.shutdown_locker = allocate_lock()
def __init__(self, ident): self.id = ident if ident != -1: self.name = "Unknown Thread " + text(ident) self.child_locker = allocate_lock() self.children = [] self.cprofiler = None self.trace_func = sys.gettrace()
def __init__(self, stream): try: self.locker = allocate_lock() self.flush = stream.flush if stream in (sys.stdout, sys.stderr): if PY3: stream = stream.buffer self.writer = _UTF8Encoder(stream).write except Exception as _: sys.stderr.write("can not handle")
def __init__(self, file): assert file from mo_files import File self.file = File(file) if self.file.exists: self.file.backup() self.file.delete() self.file_lock = allocate_lock()
def __init__(self, stream): try: self.locker = allocate_lock() self.flush = stream.flush if stream in (sys.stdout, sys.stderr): if PY3: stream = stream.buffer self.writer = _UTF8Encoder(stream).write except Exception as _: sys.stderr.write("can not handle")
def __init__(self, stream): self.locker = allocate_lock() try: if stream in (sys.stdout, sys.stderr): if PY3: self.writer = stream.write else: self.writer = _UTF8Encoder(stream).write elif hasattr(stream, 'encoding') and stream.encoding: self.writer = _UTF8Encoder(stream).write else: self.writer = stream.write except Exception as e: sys.stderr("can not handle")
def __init__(self, stream): try: self.locker = allocate_lock() self.flush = stream.flush if stream in (STDOUT, STDERR) and PY3: try: stream = stream.buffer except Exception: # SOMETIMES STDOUT IS REPLACED BY SOMETHING ELSE pass self.writer = _UTF8Encoder(stream).write except Exception as _: import sys sys.stderr.write("can not handle")
Log.warning("programming error", cause=e) finally: if please_stop: Log.note("please_stop has been requested") Log.note("done waiting for exit") def _wait_for_interrupt(please_stop): DEBUG and Log.note("wait for stop signal") try: # ALTERNATE BETWEEN please_stop CHECK AND SIGINT CHECK while not please_stop: sleep(1) # LOCKS CAN NOT BE INTERRUPTED, ONLY sleep() CAN finally: please_stop.go() MAIN_THREAD = MainThread() def stop_main_thread(signum=0, frame=None): MAIN_THREAD.please_stop.go() _signal.signal(_signal.SIGTERM, stop_main_thread) _signal.signal(_signal.SIGINT, stop_main_thread) ALL_LOCK = allocate_lock() ALL = dict() ALL[get_ident()] = MAIN_THREAD
_wait_for_interrupt(please_stop) break # if DEBUG: # Log.note("read line {{line|quote}}, count={{count}}", line=line, count=cr_count) if line == "": cr_count += 1 else: cr_count = -1000000 # NOT /dev/null if line.strip() == "exit": Log.alert("'exit' Detected! Stopping...") return def _wait_for_interrupt(please_stop): DEBUG and Log.note("inside wait-for-shutdown loop") while not please_stop: try: sleep(1) except Exception: pass MAIN_THREAD = MainThread() ALL_LOCK = allocate_lock() ALL = dict() ALL[get_ident()] = MAIN_THREAD
# Contact: Kyle Lahnakoski ([email protected]) # from __future__ import absolute_import, division, unicode_literals import importlib import inspect import sys from threading import Thread from time import time, sleep from mo_future import text, allocate_lock DEBUG = False locker = allocate_lock() expectations = [] expiry = time() + 10 monitor = None def expect(*names): """ EXPECT A LATE EXPORT INTO CALLING MODULE :param names: MODULE VARIABLES THAT WILL BE FILLED BY ANOTHER MODULE :return: PLACEHOLDERS THAT CAN BE USED UNTIL FILL HAPPENS len(output)==len(names) """ # GET MODULE OF THE CALLER