當前位置: 首頁>>代碼示例>>Python>>正文


Python _thread.get_ident方法代碼示例

本文整理匯總了Python中_thread.get_ident方法的典型用法代碼示例。如果您正苦於以下問題:Python _thread.get_ident方法的具體用法?Python _thread.get_ident怎麽用?Python _thread.get_ident使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在_thread的用法示例。


在下文中一共展示了_thread.get_ident方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: go

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def go(self):
        if self.ed.my_ident != get_ident():
            print(datetime.now(), 'EventDispatcher2: Timer.go() from wrong thread, expect Bad Stuff[tm] to happen')
            print('-' * 70)
            traceback.print_stack(file = sys.stdout)
            print('-' * 70)
            sys.stdout.flush()
        if not self.abs_time:
            if self.randomize_runs != None:
                ival = self.randomize_runs(self.ival)
            else:
                ival = self.ival
            self.etime = self.itime.getOffsetCopy(ival)
        else:
            self.etime = self.ival
            self.ival = None
            self.nticks = 1
        heappush(self.ed.tlisteners, self)
        return 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:21,代碼來源:EventDispatcher.py

示例2: __init__

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def __init__(self, freq = 100.0):
        EventDispatcher2.state_lock.acquire()
        if EventDispatcher2.ed_inum != 0:
            EventDispatcher2.state_lock.release()
            raise StdException('BZZZT, EventDispatcher2 has to be singleton!')
        EventDispatcher2.ed_inum = 1
        EventDispatcher2.state_lock.release()
        self.tcbs_lock = Lock()
        self.tlisteners = []
        self.slisteners = []
        self.signals_pending = []
        self.last_ts = MonoTime()
        self.my_ident = get_ident()
        self.elp = ElPeriodic(freq)
        self.elp.CFT_enable(signal.SIGURG)
        self.bands = [(freq, 0),] 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:18,代碼來源:EventDispatcher.py

示例3: recursive_repr

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def recursive_repr(fillvalue='...'):
    'Decorator to make a repr function return fillvalue for a recursive call'

    def decorating_function(user_function):
        repr_running = set()

        def wrapper(self):
            key = id(self), get_ident()
            if key in repr_running:
                return fillvalue
            repr_running.add(key)
            try:
                result = user_function(self)
            finally:
                repr_running.discard(key)
            return result

        # Can't use functools.wraps() here because of bootstrap issues
        wrapper.__module__ = getattr(user_function, '__module__')
        wrapper.__doc__ = getattr(user_function, '__doc__')
        wrapper.__name__ = getattr(user_function, '__name__')
        wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
        return wrapper

    return decorating_function 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:27,代碼來源:reprlib.py

示例4: release

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def release(self):
        """Release a lock, decrementing the recursion level.

        If after the decrement it is zero, reset the lock to unlocked (not owned
        by any thread), and if any other threads are blocked waiting for the
        lock to become unlocked, allow exactly one of them to proceed. If after
        the decrement the recursion level is still nonzero, the lock remains
        locked and owned by the calling thread.

        Only call this method when the calling thread owns the lock. A
        RuntimeError is raised if this method is called when the lock is
        unlocked.

        There is no return value.

        """
        if self._owner != get_ident():
            raise RuntimeError("cannot release un-acquired lock")
        self._count = count = self._count - 1
        if not count:
            self._owner = None
            self._block.release() 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:24,代碼來源:threading.py

示例5: recursive_repr

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def recursive_repr(fillvalue='...'):
    'Decorator to make a repr function return fillvalue for a recursive call'

    def decorating_function(user_function):
        repr_running = set()

        def wrapper(self):
            key = id(self), get_ident()
            if key in repr_running:
                return fillvalue
            repr_running.add(key)
            try:
                result = user_function(self)
            finally:
                repr_running.discard(key)
            return result

        # Can't use functools.wraps() here because of bootstrap issues
        wrapper.__module__ = getattr(user_function, '__module__')
        wrapper.__doc__ = getattr(user_function, '__doc__')
        wrapper.__name__ = getattr(user_function, '__name__')
        return wrapper

    return decorating_function 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:chainmap_impl.py

示例6: savepoint

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def savepoint(self):
        """
        Create a savepoint inside the current transaction. Return an
        identifier for the savepoint that will be used for the subsequent
        rollback or commit. Do nothing if savepoints are not supported.
        """
        if not self._savepoint_allowed():
            return

        thread_ident = _thread.get_ident()
        tid = str(thread_ident).replace('-', '')

        self.savepoint_state += 1
        sid = "s%s_x%d" % (tid, self.savepoint_state)

        self.validate_thread_sharing()
        self._savepoint(sid)

        return sid 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:21,代碼來源:base.py

示例7: validate_thread_sharing

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def validate_thread_sharing(self):
        """
        Validate that the connection isn't accessed by another thread than the
        one which originally created it, unless the connection was explicitly
        authorized to be shared between threads (via the `allow_thread_sharing`
        property). Raise an exception if the validation fails.
        """
        if not (self.allow_thread_sharing or self._thread_ident == _thread.get_ident()):
            raise DatabaseError(
                "DatabaseWrapper objects created in a "
                "thread can only be used in that same thread. The object "
                "with alias '%s' was created in thread id %s and this is "
                "thread id %s."
                % (self.alias, self._thread_ident, _thread.get_ident())
            )

    # ##### Miscellaneous ##### 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:19,代碼來源:base.py

示例8: __init__

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def __init__(self, loop=None, default=None):
        greenlet.__init__(self)
        if hasattr(loop, 'run'):
            if default is not None:
                raise TypeError("Unexpected argument: default")
            self.loop = loop
        elif _threadlocal.loop is not None:
            # Reuse a loop instance previously set by
            # destroying a hub without destroying the associated
            # loop. See #237 and #238.
            self.loop = _threadlocal.loop
        else:
            if default is None and get_ident() != MAIN_THREAD:
                default = False
            loop_class = _import(self.loop_class)
            if loop is None:
                loop = self.backend
            self.loop = loop_class(flags=loop, default=default)
        self._resolver = None
        self._threadpool = None
        self.format_context = _import(self.format_context) 
開發者ID:leancloud,項目名稱:satori,代碼行數:23,代碼來源:hub.py

示例9: acquire_thread

# 需要導入模塊: import _thread [as 別名]
# 或者: from _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:cherrypy,項目名稱:cherrypy,代碼行數:15,代碼來源:plugins.py

示例10: release_thread

# 需要導入模塊: import _thread [as 別名]
# 或者: from _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:cherrypy,項目名稱:cherrypy,代碼行數:8,代碼來源:plugins.py

示例11: get_ident

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def get_ident():
    """Dummy implementation of _thread.get_ident().

    Since this module should only be used when _threadmodule is not
    available, it is safe to assume that the current process is the
    only thread.  Thus a constant can be safely returned.
    """
    return -1 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:10,代碼來源:_dummy_thread.py

示例12: acquire

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def acquire(self, blocking=True, timeout=-1):
        """Acquire a lock, blocking or non-blocking.

        When invoked without arguments: if this thread already owns the lock,
        increment the recursion level by one, and return immediately. Otherwise,
        if another thread owns the lock, block until the lock is unlocked. Once
        the lock is unlocked (not owned by any thread), then grab ownership, set
        the recursion level to one, and return. If more than one thread is
        blocked waiting until the lock is unlocked, only one at a time will be
        able to grab ownership of the lock. There is no return value in this
        case.

        When invoked with the blocking argument set to true, do the same thing
        as when called without arguments, and return true.

        When invoked with the blocking argument set to false, do not block. If a
        call without an argument would block, return false immediately;
        otherwise, do the same thing as when called without arguments, and
        return true.

        When invoked with the floating-point timeout argument set to a positive
        value, block for at most the number of seconds specified by timeout
        and as long as the lock cannot be acquired.  Return true if the lock has
        been acquired, false if the timeout has elapsed.

        """
        me = get_ident()
        if self._owner == me:
            self._count = self._count + 1
            return 1
        rc = self._block.acquire(blocking, timeout)
        if rc:
            self._owner = me
            self._count = 1
        return rc 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:37,代碼來源:threading.py

示例13: _set_ident

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def _set_ident(self):
        self._ident = get_ident() 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:4,代碼來源:threading.py

示例14: _delete

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def _delete(self):
        "Remove current thread from the dict of currently running threads."

        # Notes about running with _dummy_thread:
        #
        # Must take care to not raise an exception if _dummy_thread is being
        # used (and thus this module is being used as an instance of
        # dummy_threading).  _dummy_thread.get_ident() always returns -1 since
        # there is only one thread if _dummy_thread is being used.  Thus
        # len(_active) is always <= 1 here, and any Thread instance created
        # overwrites the (if any) thread currently registered in _active.
        #
        # An instance of _MainThread is always created by 'threading'.  This
        # gets overwritten the instant an instance of Thread is created; both
        # threads return -1 from _dummy_thread.get_ident() and thus have the
        # same key in the dict.  So when the _MainThread instance created by
        # 'threading' tries to clean itself up when atexit calls this method
        # it gets a KeyError if another Thread instance was created.
        #
        # This all means that KeyError from trying to delete something from
        # _active if dummy_threading is being used is a red herring.  But
        # since it isn't if dummy_threading is *not* being used then don't
        # hide the exception.

        try:
            with _active_limbo_lock:
                del _active[get_ident()]
                # There must not be any python code between the previous line
                # and after the lock is released.  Otherwise a tracing function
                # could try to acquire the lock again in the same thread, (in
                # current_thread()), and would block.
        except KeyError:
            if 'dummy_threading' not in _sys.modules:
                raise 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:36,代碼來源:threading.py

示例15: ident

# 需要導入模塊: import _thread [as 別名]
# 或者: from _thread import get_ident [as 別名]
def ident(self):
        """Thread identifier of this thread or None if it has not been started.

        This is a nonzero integer. See the thread.get_ident() function. Thread
        identifiers may be recycled when a thread exits and another thread is
        created. The identifier is available even after the thread has exited.

        """
        assert self._initialized, "Thread.__init__() not called"
        return self._ident 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:12,代碼來源:threading.py


注:本文中的_thread.get_ident方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。