-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdispatch.py
More file actions
33 lines (29 loc) · 726 Bytes
/
dispatch.py
File metadata and controls
33 lines (29 loc) · 726 Bytes
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
33
# -*- coding: utf-8 -*-
# @Author: lock
# @Date: 2016-05-18 23:47:54
# @Last Modified by: lock
# @Last Modified time: 2016-05-18 23:47:54
from collections import deque
class Runner(object):
def __init__(self, tasks):
self.tasks = deque(tasks)
def next(self):
return self.tasks.pop()
def run(self):
while len(self.tasks):
task = self.next()
try:
next(task)
except StopIteration:
pass
else:
self.tasks.appendleft(task)
def task(name, times):
for i in range(times):
yield
print(name, i)
Runner([
task('hsfzxjy', 5),
task('Jack', 4),
task('Bob', 6)
]).run()