forked from fluentpython/example-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountdown_yf.py
More file actions
69 lines (49 loc) · 1.02 KB
/
countdown_yf.py
File metadata and controls
69 lines (49 loc) · 1.02 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from time import sleep
def countdown(n):
while n:
print('\tn ->', n)
yield n
n -= 1
sleep(1)
def foo():
for i in range(6, 3, -1):
yield i
yield from countdown(3)
#for j in foo():
# print('j ->', j)
def squares(n):
yield from [i for i in range(n)]
yield from [i*i for i in range(n)]
def squares_stupid(n):
for i in range(n):
yield i
for i in range(n):
yield i*i
#for s in squares(10):
# print(s)
def tokenize():
while True:
source = input('> ')
try:
obj = eval(source)
except BaseException:
print('*crash*')
return
try:
it = iter(obj)
except TypeError:
yield obj
return
else:
yield from it
#g = tokenize()
#for res in g:
# print(res)
from concurrent.futures import Future
def f():
f = future()
def foo(fut):
print(fut, fut.result())
f = Future()
f.add_done_callback(foo)
f.set_result(42)