-
Notifications
You must be signed in to change notification settings - Fork 0
/
threadtest.py
executable file
·62 lines (48 loc) · 1022 Bytes
/
threadtest.py
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
#!/usr/bin/python
import os
import ephem as ep
import numpy as np
import time
import defines
import matplotlib.pyplot as plt
import sqlite3 as lite
import sys
import copy
import threading
arr = []
running = True
class DrawThread(threading.Thread):
def run(self):
global running
while running:
plt.cla()
global arr
plt.plot(arr, 'bo')
plt.draw()
#print 'DrawThread'
#time.sleep(1)
class GenThread(threading.Thread):
def run(self):
global running
while running:
global arr
arr = np.random.rand(10)
#print 'GenThread'
#time.sleep(1)
def hehe(event):
global running
print '--------------------------Hehe', event.key
if event.key == '1':
running = True
if event.key == '2':
running = False
if __name__ == '__main__':
plt.ion()
fig = plt.figure(figsize=(8,5))
fig.add_subplot(111)
d = DrawThread()
d.start()
time.sleep(0.5)
g = GenThread()
g.start()
fig.canvas.mpl_connect('key_press_event', hehe)