-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathasync_test.py
More file actions
86 lines (72 loc) · 1.39 KB
/
async_test.py
File metadata and controls
86 lines (72 loc) · 1.39 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#coding:utf-8
from threading import Thread
from multiprocessing import Process, Queue
from time import sleep
import signal
def async(f):
def wrapper(*args, **kwargs):
thr = Thread(target = f, args = args, kwargs = kwargs)
thr.start()
return wrapper
def signal_handler(signal, frame):
global interrupted
interrupted = True
signal.signal(signal.SIGINT, signal_handler)
interrupted = False
@async
def time_1s():
cnt = 0
while True:
print('%ds...'%cnt)
cnt += 1
sleep(1)
@async
def A():
sleep(10)
print ("a function")
def B():
print ("b function")
class C(object):
def __init__(self):
self.p1 = 1
self.p2 = 100
self.queue = Queue()
@async
def d(self):
sleep(8)
print('\nd method')
print('\t%d'%self.p1)
#print('\t%d'%self.p2)
self.queue.put(self.p1)
self.p1 += 1
@async
def e(self):
sleep(5)
print('\ne method')
print('\t%d'%self.p1)
print('\t%d'%self.p2)
self.p2 += 1
@async
def f(self):
while True:
a = self.queue.get()
print('####%e'%a)
self.d()
time_1s()
#A()
#B()
c = C()
c.f()
c.d()
#c.e()
#print('-'*30)
#c.d()
#c.e()
#print('-'*30)
#c.d()
#c.e()
#print('-'*30)
#c.d()
#c.e()
import numpy as np
import tensorflow as tf