当前位置: 首页>>代码示例>>Python>>正文


Python _thread.get_ident方法代码示例

本文整理汇总了Python中six.moves._thread.get_ident方法的典型用法代码示例。如果您正苦于以下问题:Python _thread.get_ident方法的具体用法?Python _thread.get_ident怎么用?Python _thread.get_ident使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves._thread的用法示例。


在下文中一共展示了_thread.get_ident方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: runloop

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def runloop(self, *args, **kwargs):
        """
        meant to be called by worker thread (blocking)
        """
        self._threadID = _thread.get_ident()
        self.mutex.acquire()
        if args or kwargs:
            _job = job(*args, **kwargs)
            _job.do()
            if not _job.success:
                self.reraise(_job)

        while not self._finish:
            self.todo.wait()
            if self.job is not None:
                self.job.do()
                self.done.notify()
            else:
                break

        self.mutex.release() 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:23,代码来源:Worker.py

示例2: _profile

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def _profile(self, profiler, frame, event, arg):
        t = thread_clock()
        thread_id = _thread.get_ident()
        sampled_at = self.sampled_times.get(thread_id, 0)
        if t - sampled_at < self.interval:
            return
        self.sampled_times[thread_id] = t
        profiler.sample(frame)
        self.counter += 1
        if self.counter % 10000 == 0:
            self._clear_for_dead_threads() 
开发者ID:what-studio,项目名称:profiling,代码行数:13,代码来源:samplers.py

示例3: __repr__

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def __repr__(self, _repr_running={}):
        # Based on OrderedDict/defaultdict
        call_key = id(self), get_ident()
        if call_key in _repr_running:
            return '...'
        _repr_running[call_key] = 1
        try:
            if not self:
                return '%s(%r)' % (self.__class__.__name__, self._sort_key)
            return '%s(%r, %r)' % (self.__class__.__name__, self._sort_key,
                                   list(self.items()))
        finally:
            del _repr_running[call_key] 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:15,代码来源:data.py

示例4: __repr__

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def __repr__(self, _repr_running={}):
        'od.__repr__() <==> repr(od)'
        call_key = id(self), _get_ident()
        if call_key in _repr_running:
            return '...'
        _repr_running[call_key] = 1
        try:
            if not self:
                return '%s()' % (self.__class__.__name__,)
            return '%s(%r)' % (self.__class__.__name__, list(self.items()))
        finally:
            del _repr_running[call_key] 
开发者ID:candlepin,项目名称:virt-who,代码行数:14,代码来源:util.py

示例5: get_ident

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def get_ident():
    """Return the 'thread identifier' of the current thread."""
    return _thread.get_ident() 
开发者ID:openstack,项目名称:taskflow,代码行数:5,代码来源:threading_utils.py

示例6: _temp_dir

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def _temp_dir():
    """Construct an empty temporary dir for each thread and return the path."""
    dirname = os.path.join(tempfile.gettempdir(),
                           'local-{}.temp'.format(_thread.get_ident()))

    shutil.rmtree(dirname, True)
    os.mkdir(dirname, 0o755)
    return dirname 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:10,代码来源:local.py

示例7: test_concat_files

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def test_concat_files(self):
        """Test the _concat_files() func."""
        ident = _thread.get_ident()
        file_lst = []
        for i in six.moves.range(3):
            file_lst.append(os.path.join(tempfile.gettempdir(),
                                         '{}.{}'.format(ident, i)))
            with io.open(file_lst[-1], 'wb') as logs:
                logs.write(bytearray('{}\n'.format(i), 'ascii'))

        result = local._concat_files(file_lst)
        self.assertTrue(isinstance(result, io.TextIOWrapper))
        self.assertEqual(result.read(), u'0\n1\n2\n')

        # check that _concat_files() catches IOError for non existing file
        file_lst.append('no_such_file')
        local._concat_files(file_lst)

        for f in file_lst[:-1]:
            os.remove(f)

        # make sure that things don't break if the log file contains some
        # binary data with ord num > 128 (eg. \xc5 below) ie. not ascii
        # decodeable
        with tempfile.NamedTemporaryFile(mode='wb', delete=False) as temp:
            temp.write(b'\x42\x00\x01\xc5\x45\x0a')
            temp.seek(0)

        self.assertTrue(''.join(local._concat_files([temp.name]))) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:31,代码来源:local_test.py

示例8: acquire_thread

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def acquire_thread(self):
        """Run 'start_thread' listeners for the current thread.

        If the current thread has already been seen, any 'start_thread'
        listeners will not be run again.
        """
        thread_ident = _thread.get_ident()
        if thread_ident not in self.threads:
            # We can't just use get_ident as the thread ID
            # because some platforms reuse thread ID's.
            i = len(self.threads) + 1
            self.threads[thread_ident] = i
            self.bus.publish('start_thread', i) 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:15,代码来源:plugins.py

示例9: release_thread

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def release_thread(self):
        """Release the current thread and run 'stop_thread' listeners."""
        thread_ident = _thread.get_ident()
        i = self.threads.pop(thread_ident, None)
        if i is not None:
            self.bus.publish('stop_thread', i) 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:8,代码来源:plugins.py

示例10: call

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def call(self, *args, **kwargs):
        """
        creates a job, execute it in worker thread, and deliver result.
        if job execution raise exception, re-raise same exception
        meant to be called by non-worker threads, but this is accepted.
        blocking until job done
        """

        _job = job(*args, **kwargs)

        if self._threadID == _thread.get_ident():
            # if caller is worker thread execute immediately
            _job.do()
        else:
            # otherwise notify and wait for completion
            self.mutex.acquire()

            while self.job is not None:
                self.free.wait()

            self.job = _job
            self.todo.notify()
            self.done.wait()
            self.job = None
            self.free.notify()
            self.mutex.release()

        if _job.success:
            return _job.result
        else:
            self.reraise(_job) 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:33,代码来源:Worker.py

示例11: _safe_lock_release_py2

# 需要导入模块: from six.moves import _thread [as 别名]
# 或者: from six.moves._thread import get_ident [as 别名]
def _safe_lock_release_py2(rlock):
  """Ensure that a threading.RLock is fully released for Python 2.

  The RLock release code is:
    https://github.com/python/cpython/blob/2.7/Lib/threading.py#L187

  The RLock object's release method does not release all of its state if an
  exception is raised in the middle of its operation.  There are three pieces of
  internal state that must be cleaned up:
  - owning thread ident, an integer.
  - entry count, an integer that counts how many times the current owner has
      locked the RLock.
  - internal lock, a threading.Lock instance that handles blocking.

  Args:
    rlock: threading.RLock, lock to fully release.

  Yields:
    None.
  """
  assert isinstance(rlock, threading._RLock)
  ident = _thread.get_ident()
  expected_count = 0
  if rlock._RLock__owner == ident:
    expected_count = rlock._RLock__count
  try:
    yield
  except ThreadTerminationError:
    # Check if the current thread still owns the lock by checking if we can
    # acquire the underlying lock.
    if rlock._RLock__block.acquire(0):
      # Lock is clean, so unlock and we are done.
      rlock._RLock__block.release()
    elif rlock._RLock__owner == ident and expected_count > 0:
      # The lock is still held up the stack, so make sure the count is accurate.
      if rlock._RLock__count != expected_count:
        rlock._RLock__count = expected_count
    elif rlock._RLock__owner == ident or rlock._RLock__owner is None:
      # The internal lock is still acquired, but either this thread or no thread
      # owns it, which means it needs to be hard reset.
      rlock._RLock__owner = None
      rlock._RLock__count = 0
      rlock._RLock__block.release()
    raise
# pylint: enable=protected-access 
开发者ID:google,项目名称:openhtf,代码行数:47,代码来源:threads.py


注:本文中的six.moves._thread.get_ident方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。