Python thread.allocate_lock() Examples
The following are 30
code examples of thread.allocate_lock().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
thread
, or try the search function
.
Example #1
Source File: test_verify.py From SwiftKitten with MIT License | 7 votes |
def _run_in_multiple_threads(test1): test1() import sys try: import thread except ImportError: import _thread as thread errors = [] def wrapper(lock): try: test1() except: errors.append(sys.exc_info()) lock.release() locks = [] for i in range(10): _lock = thread.allocate_lock() _lock.acquire() thread.start_new_thread(wrapper, (_lock,)) locks.append(_lock) for _lock in locks: _lock.acquire() if errors: raise errors[0][1]
Example #2
Source File: SessionCache.py From python-for-android with Apache License 2.0 | 6 votes |
def __init__(self, maxEntries=10000, maxAge=14400): """Create a new SessionCache. @type maxEntries: int @param maxEntries: The maximum size of the cache. When this limit is reached, the oldest sessions will be deleted as necessary to make room for new ones. The default is 10000. @type maxAge: int @param maxAge: The number of seconds before a session expires from the cache. The default is 14400 (i.e. 4 hours).""" self.lock = thread.allocate_lock() # Maps sessionIDs to sessions self.entriesDict = {} #Circular list of (sessionID, timestamp) pairs self.entriesList = [(None,None)] * maxEntries self.firstIndex = 0 self.lastIndex = 0 self.maxAge = maxAge
Example #3
Source File: test_verify1.py From SwiftKitten with MIT License | 6 votes |
def _run_in_multiple_threads(test1): test1() import sys try: import thread except ImportError: import _thread as thread errors = [] def wrapper(lock): try: test1() except: errors.append(sys.exc_info()) lock.release() locks = [] for i in range(10): _lock = thread.allocate_lock() _lock.acquire() thread.start_new_thread(wrapper, (_lock,)) locks.append(_lock) for _lock in locks: _lock.acquire() if errors: raise errors[0][1]
Example #4
Source File: dashgo_driver.py From dashgo with Apache License 2.0 | 6 votes |
def __init__(self, port="/dev/ttyUSB0", baudrate=57600, timeout=0.5): self.PID_RATE = 30 # Do not change this! It is a fixed property of the Arduino PID controller. self.PID_INTERVAL = 1000 / 30 self.port = port self.baudrate = baudrate self.timeout = timeout self.encoder_count = 0 self.writeTimeout = timeout self.interCharTimeout = timeout / 30. # Keep things thread safe self.mutex = thread.allocate_lock() # An array to cache analog sensor readings self.analog_sensor_cache = [None] * self.N_ANALOG_PORTS # An array to cache digital sensor readings self.digital_sensor_cache = [None] * self.N_DIGITAL_PORTS
Example #5
Source File: test_traceback.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_with_traceback(): from thread import allocate_lock def f(): g() def g(): h() def h(): raise Exception('hello!!') try: with allocate_lock(): f() except: assert_traceback([(Line397+14, 30, 'test_traceback.py', 'test_with_traceback'), (Line397+4, 3, 'test_traceback.py', 'f'), (Line397+7, 3, 'test_traceback.py', 'g'), (Line397+10, 3, 'test_traceback.py', 'h')])
Example #6
Source File: adb.py From ironpython2 with Apache License 2.0 | 6 votes |
def __init__(self): self.debugApplication = None self.debuggingThread = None self.debuggingThreadStateHandle = None self.stackSnifferCookie = self.stackSniffer = None self.codeContainerProvider = None self.debuggingThread = None self.breakFlags = None self.breakReason = None self.appDebugger = None self.appEventConnection = None self.logicalbotframe = None # Anything at this level or below does not exist! self.currentframe = None # The frame we are currently in. self.recursiveData = [] # Data saved for each reentery on this thread. bdb.Bdb.__init__(self) self._threadprotectlock = thread.allocate_lock() self.reset()
Example #7
Source File: SessionCache.py From python-for-android with Apache License 2.0 | 6 votes |
def __init__(self, maxEntries=10000, maxAge=14400): """Create a new SessionCache. @type maxEntries: int @param maxEntries: The maximum size of the cache. When this limit is reached, the oldest sessions will be deleted as necessary to make room for new ones. The default is 10000. @type maxAge: int @param maxAge: The number of seconds before a session expires from the cache. The default is 14400 (i.e. 4 hours).""" self.lock = thread.allocate_lock() # Maps sessionIDs to sessions self.entriesDict = {} #Circular list of (sessionID, timestamp) pairs self.entriesList = [(None,None)] * maxEntries self.firstIndex = 0 self.lastIndex = 0 self.maxAge = maxAge
Example #8
Source File: recipe-511433.py From code with MIT License | 5 votes |
def __init__(self, socket): 'Initialize the Zero SPOTS Protocol object.' self.__sock = socket self.__send = _thread.allocate_lock() self.__recv = _thread.allocate_lock() self.__temp = ''
Example #9
Source File: BaseDB.py From python-for-android with Apache License 2.0 | 5 votes |
def __init__(self, filename, type): self.type = type self.filename = filename if self.filename: self.db = None else: self.db = {} self.lock = thread.allocate_lock()
Example #10
Source File: mixins.py From django-mmc with GNU General Public License v2.0 | 5 votes |
def __mmc_run_monitor(self): if self._mmc_log_instance and self._mmc_log_instance.script.real_time: with thread.allocate_lock(): if self._mmc_mon_is_run is None: self._mmc_mon_is_run = True thread.start_new_thread(self.__mmc_monitor, ())
Example #11
Source File: _pyio.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE, max_buffer_size=None): if not raw.writable(): raise IOError('"raw" argument must be writable.') _BufferedIOMixin.__init__(self, raw) if buffer_size <= 0: raise ValueError("invalid buffer size") if max_buffer_size is not None: warnings.warn("max_buffer_size is deprecated", DeprecationWarning, self._warning_stack_offset) self.buffer_size = buffer_size self._write_buf = bytearray() self._write_lock = Lock()
Example #12
Source File: _pyio.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE): """Create a new buffered reader using the given readable raw IO object. """ if not raw.readable(): raise IOError('"raw" argument must be readable.') _BufferedIOMixin.__init__(self, raw) if buffer_size <= 0: raise ValueError("invalid buffer size") self.buffer_size = buffer_size self._reset_read_buf() self._read_lock = Lock()
Example #13
Source File: dummy_thread.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def allocate_lock(): """Dummy implementation of thread.allocate_lock().""" return LockType()
Example #14
Source File: PostReplyYottu.py From TerminusBrowser with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, board, threadno): self.board = board self.threadno = threadno self.sitekey = "6Ldp2bsSAAAAAAJ5uyx_lx34lJeEpTLVkP5k04qc" self.captcha2_url = "https://www.google.com/recaptcha/api/fallback?k=" + self.sitekey self.captcha2_payload_url = "https://www.google.com/recaptcha/api2/payload" self.captcha2_image_base_url = "" self.site_ref = "https://boards.4chan.org/" self.user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0' self.captcha2_challenge_text = None # "Select all images with ducks." self.captcha2_challenge_id = None self.captcha2_image = "" # Binary image self.captcha2_image_filename = "yottu-captcha.jpg" # TODO don't save the image self.captcha2_solution = None # Array of integers associated to the captcha checkboxes, usually 0-8 self.captcha2_response = None # Response the Reply post form wants (the actual solution) self.lock = thread.allocate_lock() self.dictOutput = None self.bp = None self.dlog = DebugLog()
Example #15
Source File: rrule.py From SmartAlarmClock with MIT License | 5 votes |
def __init__(self, cache=False): if cache: self._cache = [] self._cache_lock = thread.allocate_lock() self._cache_gen = self._iter() self._cache_complete = False else: self._cache = None self._cache_complete = False self._len = None
Example #16
Source File: recipe-365640.py From code with MIT License | 5 votes |
def __init__(self): self.mutex = thread.allocate_lock()
Example #17
Source File: recipe-511433.py From code with MIT License | 5 votes |
def __init__(self, QRP): 'Initialize the Query/Reply Interface object.' self.__QRP = QRP self.__ID = 0 self.__lock = _thread.allocate_lock()
Example #18
Source File: recipe-511433.py From code with MIT License | 5 votes |
def recv_R(self, ID, timeout=None): 'Receive one reply.' if self.__error: raise self.__error if timeout is not None: if not isinstance(timeout, (float, int, long)): raise TypeError, 'timeout must be of type float, int, or long' if not timeout >= 0: raise ValueError, 'timeout must be greater than or equal to 0' anchor = [_thread.allocate_lock()] anchor[0].acquire() self.__R_lock.acquire() try: try: self.__R_anchor[ID] = anchor finally: self.__R_lock.release() except AttributeError: raise self.__error if timeout: _thread.start_new_thread(self.__R_thread, (timeout, ID)) anchor[0].acquire() try: R = anchor[1] except IndexError: if self.__error: raise self.__error raise Warning return R
Example #19
Source File: recipe-511433.py From code with MIT License | 5 votes |
def recv_Q(self, timeout=None): 'Receive one query.' if self.__error: raise self.__error if timeout is not None: if not isinstance(timeout, (float, int, long)): raise TypeError, 'timeout must be of type float, int, or long' if not timeout >= 0: raise ValueError, 'timeout must be greater than or equal to 0' self.__Q_lock.acquire() try: try: if self.__Q_packet: Q = True ID, obj = self.__Q_packet.pop() else: Q = False anchor = [_thread.allocate_lock()] anchor[0].acquire() self.__Q_anchor.append(anchor) finally: self.__Q_lock.release() except AttributeError: raise self.__error if Q: return ID, obj if timeout: _thread.start_new_thread(self.__Q_thread, (timeout, anchor)) anchor[0].acquire() try: Q = anchor[1] except IndexError: if self.__error: raise self.__error raise Warning return Q
Example #20
Source File: recipe-511433.py From code with MIT License | 5 votes |
def __init__(self, ZSP): 'Initialize the Query/Reply Protocol object.' self.__ZSP = ZSP self.__error = None self.__Q_anchor = [] self.__Q_packet = [] self.__R_anchor = {} self.__Q_lock = _thread.allocate_lock() self.__R_lock = _thread.allocate_lock() _thread.start_new_thread(self.__thread, ())
Example #21
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, id = None): if id is not None: self.id = id else: self.id = thread.get_ident() self._events = {'call' : self.handle_call, 'line' : self.handle_line, 'return' : self.handle_return, 'exception' : self.handle_exception, 'c_call' : self.handle_c_call, 'c_return' : self.handle_c_return, 'c_exception' : self.handle_c_exception, } self.cur_frame = None self.stepping = STEPPING_NONE self.unblock_work = None self._block_lock = thread.allocate_lock() self._block_lock.acquire() self._block_starting_lock = thread.allocate_lock() self._is_blocked = False self._is_working = False self.stopped_on_line = None self.detach = False self.trace_func = self.trace_func # replace self.trace_func w/ a bound method so we don't need to re-create these regularly self.prev_trace_func = None self.trace_func_stack = [] self.reported_process_loaded = False self.django_stepping = None self.is_sending = False # stackless changes if stackless is not None: self._stackless_attach() if sys.platform == 'cli': self.frames = []
Example #22
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): self.default_mode = BREAK_MODE_UNHANDLED self.break_on = { } self.handler_cache = dict(self.BUILT_IN_HANDLERS) self.handler_lock = thread.allocate_lock() self.add_exception('exceptions.IndexError', BREAK_MODE_NEVER) self.add_exception('builtins.IndexError', BREAK_MODE_NEVER) self.add_exception('exceptions.KeyError', BREAK_MODE_NEVER) self.add_exception('builtins.KeyError', BREAK_MODE_NEVER) self.add_exception('exceptions.AttributeError', BREAK_MODE_NEVER) self.add_exception('builtins.AttributeError', BREAK_MODE_NEVER) self.add_exception('exceptions.StopIteration', BREAK_MODE_NEVER) self.add_exception('builtins.StopIteration', BREAK_MODE_NEVER) self.add_exception('exceptions.GeneratorExit', BREAK_MODE_NEVER) self.add_exception('builtins.GeneratorExit', BREAK_MODE_NEVER)
Example #23
Source File: visualstudio_py_repl.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): self.lock = thread.allocate_lock()
Example #24
Source File: local.py From googleapps-message-recall with Apache License 2.0 | 5 votes |
def __init__(self): object.__setattr__(self, '__storage__', {}) object.__setattr__(self, '__lock__', allocate_lock())
Example #25
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): self.default_mode = BREAK_MODE_UNHANDLED self.break_on = { } self.handler_cache = dict(self.BUILT_IN_HANDLERS) self.handler_lock = thread.allocate_lock() self.add_exception('exceptions.IndexError', BREAK_MODE_NEVER) self.add_exception('builtins.IndexError', BREAK_MODE_NEVER) self.add_exception('exceptions.KeyError', BREAK_MODE_NEVER) self.add_exception('builtins.KeyError', BREAK_MODE_NEVER) self.add_exception('exceptions.AttributeError', BREAK_MODE_NEVER) self.add_exception('builtins.AttributeError', BREAK_MODE_NEVER) self.add_exception('exceptions.StopIteration', BREAK_MODE_NEVER) self.add_exception('builtins.StopIteration', BREAK_MODE_NEVER) self.add_exception('exceptions.GeneratorExit', BREAK_MODE_NEVER) self.add_exception('builtins.GeneratorExit', BREAK_MODE_NEVER)
Example #26
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, id = None): if id is not None: self.id = id else: self.id = thread.get_ident() self._events = {'call' : self.handle_call, 'line' : self.handle_line, 'return' : self.handle_return, 'exception' : self.handle_exception, 'c_call' : self.handle_c_call, 'c_return' : self.handle_c_return, 'c_exception' : self.handle_c_exception, } self.cur_frame = None self.stepping = STEPPING_NONE self.unblock_work = None self._block_lock = thread.allocate_lock() self._block_lock.acquire() self._block_starting_lock = thread.allocate_lock() self._is_blocked = False self._is_working = False self.stopped_on_line = None self.detach = False self.trace_func = self.trace_func # replace self.trace_func w/ a bound method so we don't need to re-create these regularly self.prev_trace_func = None self.trace_func_stack = [] self.reported_process_loaded = False self.django_stepping = None self.is_sending = False # stackless changes if stackless is not None: self._stackless_attach() if sys.platform == 'cli': self.frames = []
Example #27
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): self.default_mode = BREAK_MODE_UNHANDLED self.break_on = { } self.handler_cache = dict(self.BUILT_IN_HANDLERS) self.handler_lock = thread.allocate_lock() self.add_exception('exceptions.IndexError', BREAK_MODE_NEVER) self.add_exception('builtins.IndexError', BREAK_MODE_NEVER) self.add_exception('exceptions.KeyError', BREAK_MODE_NEVER) self.add_exception('builtins.KeyError', BREAK_MODE_NEVER) self.add_exception('exceptions.AttributeError', BREAK_MODE_NEVER) self.add_exception('builtins.AttributeError', BREAK_MODE_NEVER) self.add_exception('exceptions.StopIteration', BREAK_MODE_NEVER) self.add_exception('builtins.StopIteration', BREAK_MODE_NEVER) self.add_exception('exceptions.GeneratorExit', BREAK_MODE_NEVER) self.add_exception('builtins.GeneratorExit', BREAK_MODE_NEVER)
Example #28
Source File: visualstudio_py_repl.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): self.lock = thread.allocate_lock()
Example #29
Source File: visualstudio_py_repl.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): self.lock = thread.allocate_lock()
Example #30
Source File: visualstudio_py_debugger.py From iot-utilities with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): self.default_mode = BREAK_MODE_UNHANDLED self.break_on = { } self.handler_cache = dict(self.BUILT_IN_HANDLERS) self.handler_lock = thread.allocate_lock() self.add_exception('exceptions.IndexError', BREAK_MODE_NEVER) self.add_exception('builtins.IndexError', BREAK_MODE_NEVER) self.add_exception('exceptions.KeyError', BREAK_MODE_NEVER) self.add_exception('builtins.KeyError', BREAK_MODE_NEVER) self.add_exception('exceptions.AttributeError', BREAK_MODE_NEVER) self.add_exception('builtins.AttributeError', BREAK_MODE_NEVER) self.add_exception('exceptions.StopIteration', BREAK_MODE_NEVER) self.add_exception('builtins.StopIteration', BREAK_MODE_NEVER) self.add_exception('exceptions.GeneratorExit', BREAK_MODE_NEVER) self.add_exception('builtins.GeneratorExit', BREAK_MODE_NEVER)