@@ -9,7 +9,8 import numpy | |||||
9 |
|
9 | |||
10 | from time import sleep |
|
10 | from time import sleep | |
11 | from Queue import Queue |
|
11 | from Queue import Queue | |
12 |
from threading import |
|
12 | from threading import Lock | |
|
13 | # from threading import Thread | |||
13 |
|
14 | |||
14 | from schainpy.model.proc.jroproc_base import Operation |
|
15 | from schainpy.model.proc.jroproc_base import Operation | |
15 | from schainpy.model.serializer.data import obj2Dict, dict2Obj |
|
16 | from schainpy.model.serializer.data import obj2Dict, dict2Obj | |
@@ -64,33 +65,39 class Plotter(Operation): | |||||
64 |
|
65 | |||
65 | self.__queue.put(packDict) |
|
66 | self.__queue.put(packDict) | |
66 |
|
67 | |||
67 |
class Plot |
|
68 | # class PlotManager(Thread): | |
68 |
|
69 | class PlotManager(): | ||
69 | __stop = False |
|
70 | __stop = False | |
70 |
|
71 | |||
71 | def __init__(self, plotter_queue): |
|
72 | def __init__(self, plotter_queue): | |
72 |
|
73 | |||
73 | Thread.__init__(self) |
|
74 | # Thread.__init__(self) | |
74 |
|
75 | # self.setDaemon(True) | ||
75 | self.setDaemon(True) |
|
|||
76 |
|
76 | |||
77 | self.__queue = plotter_queue |
|
77 | self.__queue = plotter_queue | |
|
78 | self.__lock = Lock() | |||
78 |
|
79 | |||
79 | self.plotInstanceDict = {} |
|
80 | self.plotInstanceDict = {} | |
80 | self.__stop = False |
|
81 | self.__stop = False | |
81 |
|
82 | |||
82 | def run(self): |
|
83 | def run(self): | |
83 |
|
84 | |||
84 | while True: |
|
85 | if self.__queue.empty(): | |
85 |
|
86 | return | ||
86 | if self.__stop: |
|
87 | ||
87 | break |
|
88 | self.__lock.acquire() | |
|
89 | ||||
|
90 | # if self.__queue.full(): | |||
|
91 | # for i in range(int(self.__queue.qsize()/2)): | |||
|
92 | # serial_data = self.__queue.get() | |||
|
93 | # self.__queue.task_done() | |||
88 |
|
94 | |||
89 |
|
|
95 | n = int(self.__queue.qsize()/3 + 1) | |
90 | sleep(0.1) |
|
96 | ||
91 | continue |
|
97 | for i in range(n): | |
92 |
|
98 | |||
93 |
serial_data = self.__queue.get( |
|
99 | serial_data = self.__queue.get() | |
|
100 | self.__queue.task_done() | |||
94 |
|
101 | |||
95 | plot_id = serial_data['id'] |
|
102 | plot_id = serial_data['id'] | |
96 | plot_name = serial_data['name'] |
|
103 | plot_name = serial_data['name'] | |
@@ -106,6 +113,25 class PlotterManager(Thread): | |||||
106 | plotter = self.plotInstanceDict[plot_id] |
|
113 | plotter = self.plotInstanceDict[plot_id] | |
107 | plotter.run(dataPlot, plot_id, **kwargs) |
|
114 | plotter.run(dataPlot, plot_id, **kwargs) | |
108 |
|
115 | |||
|
116 | ||||
|
117 | ||||
|
118 | self.__lock.release() | |||
|
119 | ||||
109 | def stop(self): |
|
120 | def stop(self): | |
110 |
|
121 | |||
111 |
self.__ |
|
122 | self.__lock.acquire() | |
|
123 | ||||
|
124 | self.__stop = True | |||
|
125 | ||||
|
126 | self.__lock.release() | |||
|
127 | ||||
|
128 | def close(self): | |||
|
129 | ||||
|
130 | self.__lock.acquire() | |||
|
131 | ||||
|
132 | for plot_id in self.plotInstanceDict.keys(): | |||
|
133 | plotter = self.plotInstanceDict[plot_id] | |||
|
134 | plotter.close() | |||
|
135 | ||||
|
136 | self.__lock.release() | |||
|
137 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now