MCPcopy Create free account
hub / github.com/ActiveState/code / Affinity

Class Affinity

recipes/Python/578151_affinitypy/recipe-578151.py:26–45  ·  view source on GitHub ↗

Affinity() -> Affinity instance

Source from the content-addressed store, hash-verified

24################################################################################
25
26class Affinity:
27
28 "Affinity() -> Affinity instance"
29
30 slots('thread, action')
31
32 def __init__(self):
33 "Initializes instance with thread identity and job queue."
34 self.__thread = _thread.get_ident()
35 self.__action = queue.Queue()
36
37 def __call__(self, func, *args, **kwargs):
38 "Executes function on creating thread and returns result."
39 if _thread.get_ident() == self.__thread:
40 while not self.__action.empty():
41 self.__action.get_nowait()()
42 return func(*args, **kwargs)
43 delegate = _Delegate(func, args, kwargs)
44 self.__action.put_nowait(delegate)
45 return delegate.value
46
47################################################################################
48

Callers

nothing calls this directly

Calls 1

slotsFunction · 0.70

Tested by

no test coverage detected