本文整理汇总了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: 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
示例5: test_elapsed
# 需要导入模块: import thread [as 别名]
# 或者: from thread import get_ident [as 别名]
def test_elapsed(self):
result = self._state.get_elapsed()
self.assertTrue(isinstance(result, list))
self.assertEqual([], result)
now = time.time()
self._state.add_elapsed(now, 'abc', 13.4)
# expect to get a list of one elapsed time records.
result = self._state.get_elapsed()
self.assertTrue(isinstance(result, list))
self.assertEqual(1, len(result))
self.assertEqual(now, result[0].start_time)
self.assertEqual('abc', result[0].what)
self.assertEqual(13.4, result[0].elapsed_seconds)
self.assertEqual(thread.get_ident(), result[0].thread_identifier)
# Calling get_elapsed() should clear the list of elapsed times.
result = self._state.get_elapsed()
self.assertTrue(isinstance(result, list))
self.assertEqual([], result)
示例6: test_thread_state
# 需要导入模块: import thread [as 别名]
# 或者: from thread import get_ident [as 别名]
def test_thread_state(self):
# some extra thread-state tests driven via _testcapi
def target():
idents = []
def callback():
idents.append(thread.get_ident())
_testcapi._test_thread_state(callback)
a = b = callback
time.sleep(1)
# Check our main thread is in the list exactly 3 times.
self.assertEqual(idents.count(thread.get_ident()), 3,
"Couldn't find main thread correctly in the list")
target()
t = threading.Thread(target=target)
t.start()
t.join()
示例7: __repr__
# 需要导入模块: import thread [as 别名]
# 或者: from 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__, self.items())
finally:
del _repr_running[call_key]
示例8: 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
################################################################################
### OrderedDict
################################################################################
示例9: 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."
# pylint: disable=missing-docstring
# Copied from reprlib in Python 3
# https://hg.python.org/cpython/file/3.6/Lib/reprlib.py
def decorating_function(user_function):
repr_running = set()
@wraps(user_function)
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
return wrapper
return decorating_function
###############################################################################
# END Python 2/3 Shims
###############################################################################
示例10: 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
# from collections 3.2.1
示例11: wait
# 需要导入模块: import thread [as 别名]
# 或者: from thread import get_ident [as 别名]
def wait(self):
"""Invoked from each client's thread to wait for the next frame."""
ident = get_ident()
if ident not in self.events:
# this is a new client
# add an entry for it in the self.events dict
# each entry has two elements, a threading.Event() and a timestamp
self.events[ident] = [threading.Event(), time.time()]
return self.events[ident][0].wait()
示例12: clear
# 需要导入模块: import thread [as 别名]
# 或者: from thread import get_ident [as 别名]
def clear(self):
"""Invoked from each client's thread after a frame was processed."""
self.events[get_ident()][0].clear()
示例13: 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
# from collections 3.2.1
示例14: _recursive_guard
# 需要导入模块: import thread [as 别名]
# 或者: from thread import get_ident [as 别名]
def _recursive_guard(fillvalue='...'):
"""
Like the python 3.2 reprlib.recursive_repr, but forwards *args and **kwargs
Decorates a function such that if it calls itself with the same first
argument, it returns `fillvalue` instead of recursing.
Largely copied from reprlib.recursive_repr
"""
def decorating_function(f):
repr_running = set()
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
key = id(self), get_ident()
if key in repr_running:
return fillvalue
repr_running.add(key)
try:
return f(self, *args, **kwargs)
finally:
repr_running.discard(key)
return wrapper
return decorating_function
# gracefully handle recursive calls, when object arrays contain themselves
示例15: __init__
# 需要导入模块: import thread [as 别名]
# 或者: from thread import get_ident [as 别名]
def __init__(self):
object.__setattr__(self, "__storage__", {})
object.__setattr__(self, "__ident_func__", get_ident)