本文整理汇总了Python中pypy.module.thread.ll_thread.get_ident函数的典型用法代码示例。如果您正苦于以下问题:Python get_ident函数的具体用法?Python get_ident怎么用?Python get_ident使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_ident函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setdict
def setdict(self, space, w_dict):
if not space.is_true(space.isinstance(w_dict, space.w_dict)):
raise OperationError(space.w_TypeError,
space.wrap("setting dictionary to a non-dict"))
self.getdict() # force a dict to exist first
ident = thread.get_ident()
self.dicts[ident] = w_dict
示例2: f
def f():
state.data = []
state.threadlocals = gil.GILThreadLocals()
state.threadlocals.setup_threads(space)
thread.gc_thread_prepare()
subident = thread.start_new_thread(bootstrap, ())
mainident = thread.get_ident()
runme()
still_waiting = 3000
while len(state.data) < 2*N:
if not still_waiting:
raise ValueError("time out")
still_waiting -= 1
if not we_are_translated(): gil.before_external_call()
time.sleep(0.01)
if not we_are_translated(): gil.after_external_call()
i1 = i2 = 0
for tid, i in state.data:
if tid == mainident:
assert i == i1; i1 += 1
elif tid == subident:
assert i == i2; i2 += 1
else:
assert 0
assert i1 == N
assert i2 == N
return len(state.data)
示例3: run
def run(space, w_callable, args):
try:
space.call_args(w_callable, args)
except OperationError, e:
if not e.match(space, space.w_SystemExit):
ident = thread.get_ident()
where = 'thread %d started by ' % ident
e.write_unraisable(space, where, w_callable)
e.clear(space)
示例4: get_ident
def get_ident(space):
"""Return a non-zero integer that uniquely identifies the current thread
amongst other threads that exist simultaneously.
This may be used to identify per-thread resources.
Even though on some platforms threads identities may appear to be
allocated consecutive numbers starting at 1, this behavior should not
be relied upon, and the number should be seen purely as a magic cookie.
A thread's identity may be reused for another thread after it exits."""
ident = thread.get_ident()
return space.wrap(ident)
示例5: getvalue
def getvalue(self):
ident = thread.get_ident()
if ident == self._mostrecentkey:
result = self._mostrecentvalue
else:
value = self._valuedict.get(ident, None)
# slow path: update the minicache
self._mostrecentkey = ident
self._mostrecentvalue = value
result = value
return result
示例6: setvalue
def setvalue(self, value):
ident = thread.get_ident()
if value is not None:
if len(self._valuedict) == 0:
self._mainthreadident = ident
self._valuedict[ident] = value
else:
try:
del self._valuedict[ident]
except KeyError:
pass
示例7: leave_thread
def leave_thread(self, space):
"Notification that the current thread is about to stop."
try:
ec = space.getexecutioncontext()
while ec.thread_exit_funcs:
exit_func, w_obj = ec.thread_exit_funcs.pop()
exit_func(w_obj)
finally:
ident = thread.get_ident()
try:
del self._valuedict[ident]
except KeyError:
pass
示例8: setvalue
def setvalue(self, value):
ident = thread.get_ident()
if value is not None:
if len(self._valuedict) == 0:
self._mainthreadident = ident
self._valuedict[ident] = value
else:
try:
del self._valuedict[ident]
except KeyError:
pass
# update the minicache to prevent it from containing an outdated value
self._mostrecentkey = ident
self._mostrecentvalue = value
示例9: runme
def runme(main=False):
j = 0
for i in range(N + [-skew, skew][main]):
state.datalen1 += 1 # try to crash if the GIL is not
state.datalen2 += 1 # correctly acquired
state.data.append((thread.get_ident(), i))
state.datalen3 += 1
state.datalen4 += 1
assert state.datalen1 == len(state.data)
assert state.datalen2 == len(state.data)
assert state.datalen3 == len(state.data)
assert state.datalen4 == len(state.data)
debug_print(main, i, state.datalen4)
gil.do_yield_thread()
assert i == j
j += 1
示例10: getdict
def getdict(self, space):
ident = thread.get_ident()
try:
w_dict = self.dicts[ident]
except KeyError:
# create a new dict for this thread
w_dict = self.dicts[ident] = space.newdict(instance=True)
# call __init__
try:
w_self = space.wrap(self)
w_type = space.type(w_self)
w_init = space.getattr(w_type, space.wrap("__init__"))
space.call_obj_args(w_init, w_self, self.initargs)
except:
# failed, forget w_dict and propagate the exception
del self.dicts[ident]
raise
# ready
space.threadlocals.atthreadexit(space, finish_thread, self)
return w_dict
示例11: PyThread_get_thread_ident
def PyThread_get_thread_ident(space):
return ll_thread.get_ident()
示例12: __init__
def __init__(self, space, initargs):
self.initargs = initargs
ident = thread.get_ident()
self.dicts = {ident: space.newdict(instance=True)}
示例13: _ssl_thread_id_function
def _ssl_thread_id_function():
from pypy.module.thread import ll_thread
return rffi.cast(rffi.LONG, ll_thread.get_ident())
示例14: __init__
def __init__(self, space, initargs):
self.space = space
self.initargs = initargs.normalize()
ident = thread.get_ident()
self.dicts = {ident: space.newdict()}
示例15: finish_thread
def finish_thread(w_obj):
assert isinstance(w_obj, Local)
ident = thread.get_ident()
del w_obj.dicts[ident]