本文整理汇总了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
示例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),]
示例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
示例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()
示例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
示例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
示例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 #####
示例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)
示例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)
示例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)
示例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
示例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
示例13: _set_ident
# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import get_ident [as 别名]
def _set_ident(self):
self._ident = get_ident()
示例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
示例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