def handler_for_inline_t ask self grab task if isinstance task types G

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def handler_for_inline_task(self, grab, task):
if isinstance(task, types.GeneratorType):
coroutines_stack = []
sendval = None
origin_task_generator = task
target = origin_task_generator
else:
coroutines_stack = task.coroutines_stack
sendval = grab
origin_task_generator = task.origin_task_generator
target = origin_task_generator
while True:
try:
result = target.send(sendval)
if isinstance(result, types.GeneratorType):
coroutines_stack.append(target)
sendval = None
target = result
origin_task_generator = target
else:
new_task = result
new_task.origin_task_generator = origin_task_generator
new_task.coroutines_stack = coroutines_stack
self.add_task(new_task)
return
except StopIteration:
if coroutines_stack:
target = coroutines_stack.pop()
origin_task_generator = target
else:
return