4
4
based on EpicsApps.StepScan.
5
5
6
6
"""
7
+ from __future__ import print_function
8
+
7
9
import os
8
10
import time
9
11
import json
@@ -31,10 +33,11 @@ def __init__(self, verbose=False, pidfile=None,
31
33
** conn_kws ):
32
34
self .verbose = verbose
33
35
self .scandb = ScanDB (** conn_kws )
36
+ self .set_state (0 )
37
+
34
38
self .state = 0
35
39
self .last = self .pulse = - 1
36
40
self .last_move_time = 0
37
- self .set_state (0 )
38
41
self .config = None
39
42
self .dead_time = 0.5
40
43
self .id_lookahead = 2
@@ -46,7 +49,6 @@ def __init__(self, verbose=False, pidfile=None,
46
49
self .pulsecount_pv = PV (pulsecount_pvname )
47
50
if heartbeat_pvname is not None :
48
51
self .heartbeat_pv = PV (heartbeat_pvname )
49
-
50
52
self .connected = False
51
53
self .connect ()
52
54
@@ -64,17 +66,14 @@ def connect(self):
64
66
self .idtaper_pv = PV ('%sTaperEnergy' % pvroot )
65
67
self .idtaperset_pv = PV ('%sTaperEnergySet' % pvroot )
66
68
67
-
68
-
69
69
self .xps = NewportXPS (self .config ['host' ],
70
70
username = self .config ['username' ],
71
71
password = self .config ['password' ],
72
72
group = self .config ['group' ],
73
73
outputs = self .config ['outputs' ])
74
- time .sleep (0.25 )
74
+ time .sleep (0.1 )
75
75
self .connected = True
76
76
77
-
78
77
def qxafs_connect_counters (self ):
79
78
self .counters = []
80
79
time .sleep (0.1 )
@@ -203,20 +202,22 @@ def get_state(self):
203
202
val = self .scandb .get_info (key = 'qxafs_running' , default = 0 )
204
203
return int (val )
205
204
206
- def get_lastupdate ():
205
+ def get_lastupdate (self ):
207
206
if self .heartbeat_pv is not None :
208
207
return int (self .heartbeat_pv .get (as_string = True ))
209
208
return - 1
210
209
211
- def kill_old_process ():
210
+ def kill_old_process (self ):
211
+ print ("kill old " , self .heartbeat_pv )
212
212
if self .heartbeat_pv is not None :
213
- self .heartbeat_pv .put (- 1 )
213
+ self .heartbeat_pv .put ("-1" )
214
214
215
215
pid = None
216
216
with open (self .pidfile ) as fh :
217
217
pid = int (fh .readlines ()[0 ][:- 1 ])
218
+
218
219
if pid is not None :
219
- print (' killing pid=' , pid , ' at ' , time .ctime ())
220
+ print ('killing pid=' , pid , ' at ' , time .ctime ())
220
221
os .system ("kill -9 %d" % pid )
221
222
time .sleep (1.0 )
222
223
@@ -238,57 +239,4 @@ def mainloop(self):
238
239
time .sleep (1.0 )
239
240
if self .heartbeat_pv is not None :
240
241
self .heartbeat_pv .put ("%i" % int (time .time ()))
241
- # self.set_state(0)
242
-
243
-
244
- def start (verbose = False ):
245
- """save pid for later killing, start process"""
246
- fpid = open (PIDFILE , 'w' )
247
- fpid .write ("%d\n " % os .getpid () )
248
- fpid .close ()
249
-
250
- watcher = QXAFS_ScanWatcher (verbose = verbose , ** conn )
251
- watcher .mainloop ()
252
-
253
- def get_lastupdate ():
254
- try :
255
- return int (caget (HEARTBEAT_PVNAME , as_string = True ))
256
- except :
257
- return - 1
258
-
259
- def kill_old_process ():
260
- try :
261
- caput (HEARTBEAT_PVNAME , '1' )
262
- finp = open (PIDFILE )
263
- pid = int (finp .readlines ()[0 ][:- 1 ])
264
- finp .close ()
265
- cmd = "kill -9 %d" % pid
266
- os .system (cmd )
267
- print ( ' killing pid=' , pid , ' at ' , time .ctime ())
268
- except :
269
- pass
270
-
271
-
272
- def run_qxafs_monitor ():
273
- usage = "usage: %prog [options] file(s)"
274
-
275
- parser = OptionParser (usage = usage , prog = "qxafs_monitor" , version = "1" )
276
-
277
- parser .add_option ("-f" , "--force" , dest = "force" , action = "store_true" ,
278
- default = False , help = "force restart, default = False" )
279
- parser .add_option ("-v" , "--verbose" , dest = "verbose" , action = "store_true" ,
280
- default = False , help = "verbose messages, default = False" )
281
-
282
-
283
- (options , args ) = parser .parse_args ()
284
-
285
- oldtime = get_lastupdate ()
286
- if (options .force or (abs (time .time () - oldtime ) > 120.0 )):
287
- kill_old_process ()
288
- time .sleep (1.0 )
289
- start (verbose = options .verbose )
290
- else :
291
- print ( 'QXAFS Monitor running OK at ' , time .ctime ())
292
-
293
- if __name__ == '__main__' :
294
- run_qxafs_monitor ()
242
+ #
0 commit comments