__init__.py (3146B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\uthread2_plugins\__init__.py 2 from future.utils import raise_ 3 import sys 4 _all_implementations = [] 5 STACKLESS_TRACING_ENABLED_KEY = 'stackless_tracing_enabled' 6 7 def pop_stackless_tracing_enabled(kwargs): 8 return (kwargs.pop(STACKLESS_TRACING_ENABLED_KEY, True), kwargs) 9 10 11 class BaseUthreadImpl(object): 12 13 def __init__(self): 14 _all_implementations.append(self) 15 16 def map(self, func, sequence): 17 sequence = list(sequence) 18 resultmap = [None] * len(sequence) 19 exc_infos = [] 20 21 def inner(ind_and_item): 22 ind, item = ind_and_item 23 try: 24 result = func(item) 25 except Exception: 26 exc_infos.append(sys.exc_info()) 27 return 28 29 resultmap[ind] = result 30 31 tasklets = [ self.start_tasklet(inner, o) for o in enumerate(sequence) ] 32 while tasklets: 33 self.yield_() 34 while tasklets and not tasklets[-1].is_alive(): 35 tasklets.pop() 36 37 if any(exc_infos): 38 ei = exc_infos[0] 39 raise_(ei[0], ei[1], ei[2]) 40 41 return resultmap 42 43 def sleep(self, seconds): 44 raise NotImplementedError() 45 46 def sleep_sim(self, seconds): 47 return self.sleep(seconds) 48 49 def start_tasklet(self, func, *args, **kwargs): 50 raise NotImplementedError() 51 52 def yield_(self): 53 raise NotImplementedError() 54 55 def get_current(self): 56 raise NotImplementedError() 57 58 def wait(self, tasklets, timeout): 59 raise NotImplementedError() 60 61 def Event(self): 62 raise NotImplementedError() 63 64 def BlockingChannel(self): 65 raise NotImplementedError() 66 67 def PumpChannel(self): 68 raise NotImplementedError() 69 70 def QueueChannel(self): 71 raise NotImplementedError() 72 73 def Semaphore(self): 74 raise NotImplementedError() 75 76 77 class BaseSemaphore(object): 78 79 def acquire(self): 80 raise NotImplementedError() 81 82 def release(self): 83 raise NotImplementedError() 84 85 def __enter__(self): 86 raise NotImplementedError() 87 88 def __exit__(self, exc, val, tb): 89 raise NotImplementedError() 90 91 92 class BaseChannel(object): 93 94 def send(self, data): 95 raise NotImplementedError() 96 97 def receive(self): 98 raise NotImplementedError() 99 100 101 class Tasklet(object): 102 103 def is_alive(self): 104 raise NotImplementedError() 105 106 def kill(self): 107 raise NotImplementedError() 108 109 def get(self): 110 raise NotImplementedError() 111 112 def IsAlive(self, *args, **kwargs): 113 return self.is_alive(*args, **kwargs) 114 115 def Kill(self, *args, **kwargs): 116 return self.kill(*args, **kwargs) 117 118 119 _main_impl = None 120 121 def set_implementation(impl): 122 global _main_impl 123 _main_impl = impl 124 125 126 def get_implementation(): 127 if _main_impl is not None: 128 return _main_impl 129 if _all_implementations: 130 return _all_implementations[0] 131 raise RuntimeError('No uthread implementations registered.') 132 133 134 def get_all_implementations(): 135 return list(_all_implementations)