@@ -3,15 +3,19 Created on Jul 9, 2014 | |||||
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os, sys | |
7 | import datetime |
|
7 | import datetime | |
8 | import numpy |
|
8 | import numpy | |
|
9 | import traceback | |||
9 |
|
10 | |||
10 | from time import sleep |
|
11 | from time import sleep | |
11 | from Queue import Queue |
|
12 | from Queue import Queue | |
12 | from threading import Lock |
|
13 | from threading import Lock | |
13 | # from threading import Thread |
|
14 | # from threading import Thread | |
14 |
|
15 | |||
|
16 | import schainpy | |||
|
17 | import schainpy.admin | |||
|
18 | ||||
15 | from schainpy.model.proc.jroproc_base import Operation |
|
19 | from schainpy.model.proc.jroproc_base import Operation | |
16 | from schainpy.model.serializer.data import obj2Dict, dict2Obj |
|
20 | from schainpy.model.serializer.data import obj2Dict, dict2Obj | |
17 | from jroplot_correlation import * |
|
21 | from jroplot_correlation import * | |
@@ -67,9 +71,20 class Plotter(Operation): | |||||
67 |
|
71 | |||
68 | # class PlotManager(Thread): |
|
72 | # class PlotManager(Thread): | |
69 | class PlotManager(): |
|
73 | class PlotManager(): | |
|
74 | ||||
|
75 | __err = False | |||
70 | __stop = False |
|
76 | __stop = False | |
|
77 | __realtime = False | |||
|
78 | ||||
71 | controllerThreadObj = None |
|
79 | controllerThreadObj = None | |
72 |
|
80 | |||
|
81 | plotterList = ['Scope', | |||
|
82 | 'SpectraPlot', 'RTIPlot', | |||
|
83 | 'CrossSpectraPlot', 'CoherenceMap', | |||
|
84 | 'PowerProfilePlot', 'Noise', 'BeaconPhase', | |||
|
85 | 'CorrelationPlot', | |||
|
86 | 'SpectraHeisScope','RTIfromSpectraHeis'] | |||
|
87 | ||||
73 | def __init__(self, plotter_queue): |
|
88 | def __init__(self, plotter_queue): | |
74 |
|
89 | |||
75 | # Thread.__init__(self) |
|
90 | # Thread.__init__(self) | |
@@ -79,13 +94,53 class PlotManager(): | |||||
79 | self.__lock = Lock() |
|
94 | self.__lock = Lock() | |
80 |
|
95 | |||
81 | self.plotInstanceDict = {} |
|
96 | self.plotInstanceDict = {} | |
|
97 | ||||
|
98 | self.__err = False | |||
82 | self.__stop = False |
|
99 | self.__stop = False | |
|
100 | self.__realtime = False | |||
|
101 | ||||
|
102 | def __handleError(self, name="", send_email=False): | |||
|
103 | ||||
|
104 | err = traceback.format_exception(sys.exc_info()[0], | |||
|
105 | sys.exc_info()[1], | |||
|
106 | sys.exc_info()[2]) | |||
|
107 | ||||
|
108 | print "***** Error occurred in PlotManager *****" | |||
|
109 | print "***** [%s]: %s" %(name, err[-1]) | |||
|
110 | ||||
|
111 | message = "\nError ocurred in %s:\n" %name | |||
|
112 | message += "".join(err) | |||
|
113 | ||||
|
114 | sys.stderr.write(message) | |||
|
115 | ||||
|
116 | if not send_email: | |||
|
117 | return | |||
|
118 | ||||
|
119 | import socket | |||
|
120 | ||||
|
121 | subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, name) | |||
|
122 | ||||
|
123 | subtitle = "%s:\n" %(name) | |||
|
124 | subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname()) | |||
|
125 | subtitle += "Working directory: %s\n" %os.path.abspath("./") | |||
|
126 | # subtitle += "Configuration file: %s\n" %self.filename | |||
|
127 | subtitle += "Time: %s\n" %str(datetime.datetime.now()) | |||
|
128 | ||||
|
129 | adminObj = schainpy.admin.SchainNotify() | |||
|
130 | adminObj.sendAlert(message=message, | |||
|
131 | subject=subject, | |||
|
132 | subtitle=subtitle) | |||
83 |
|
133 | |||
84 | def run(self): |
|
134 | def run(self): | |
85 |
|
135 | |||
86 | if self.__queue.empty(): |
|
136 | if self.__queue.empty(): | |
87 | return |
|
137 | return | |
88 |
|
138 | |||
|
139 | if self.__err: | |||
|
140 | serial_data = self.__queue.get() | |||
|
141 | self.__queue.task_done() | |||
|
142 | return | |||
|
143 | ||||
89 | self.__lock.acquire() |
|
144 | self.__lock.acquire() | |
90 |
|
145 | |||
91 | # if self.__queue.full(): |
|
146 | # if self.__queue.full(): | |
@@ -115,7 +170,12 class PlotManager(): | |||||
115 | self.plotInstanceDict[plot_id] = className() |
|
170 | self.plotInstanceDict[plot_id] = className() | |
116 |
|
171 | |||
117 | plotter = self.plotInstanceDict[plot_id] |
|
172 | plotter = self.plotInstanceDict[plot_id] | |
118 | plotter.run(dataPlot, plot_id, **kwargs) |
|
173 | try: | |
|
174 | plotter.run(dataPlot, plot_id, **kwargs) | |||
|
175 | except: | |||
|
176 | self.__err = True | |||
|
177 | self.__handleError(plot_name, send_email=True) | |||
|
178 | break | |||
119 |
|
179 | |||
120 | self.__lock.release() |
|
180 | self.__lock.release() | |
121 |
|
181 | |||
@@ -164,4 +224,14 class PlotManager(): | |||||
164 | while not self.isEmpty(): |
|
224 | while not self.isEmpty(): | |
165 | self.run() |
|
225 | self.run() | |
166 |
|
226 | |||
167 | self.close() No newline at end of file |
|
227 | self.close() | |
|
228 | ||||
|
229 | def isErrorDetected(self): | |||
|
230 | ||||
|
231 | self.__lock.acquire() | |||
|
232 | ||||
|
233 | err = self.__err | |||
|
234 | ||||
|
235 | self.__lock.release() | |||
|
236 | ||||
|
237 | return err No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now