Skip to content

Commit f7422bf

Browse files
committed
more fixes to qxafs_monitor
1 parent 39d4dee commit f7422bf

File tree

1 file changed

+12
-64
lines changed

1 file changed

+12
-64
lines changed

lib/qxafs_monitor.py

+12-64
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
based on EpicsApps.StepScan.
55
66
"""
7+
from __future__ import print_function
8+
79
import os
810
import time
911
import json
@@ -31,10 +33,11 @@ def __init__(self, verbose=False, pidfile=None,
3133
**conn_kws):
3234
self.verbose = verbose
3335
self.scandb = ScanDB(**conn_kws)
36+
self.set_state(0)
37+
3438
self.state = 0
3539
self.last = self.pulse = -1
3640
self.last_move_time = 0
37-
self.set_state(0)
3841
self.config = None
3942
self.dead_time = 0.5
4043
self.id_lookahead = 2
@@ -46,7 +49,6 @@ def __init__(self, verbose=False, pidfile=None,
4649
self.pulsecount_pv = PV(pulsecount_pvname)
4750
if heartbeat_pvname is not None:
4851
self.heartbeat_pv = PV(heartbeat_pvname)
49-
5052
self.connected = False
5153
self.connect()
5254

@@ -64,17 +66,14 @@ def connect(self):
6466
self.idtaper_pv = PV('%sTaperEnergy' % pvroot)
6567
self.idtaperset_pv = PV('%sTaperEnergySet' % pvroot)
6668

67-
68-
6969
self.xps = NewportXPS(self.config['host'],
7070
username=self.config['username'],
7171
password=self.config['password'],
7272
group=self.config['group'],
7373
outputs=self.config['outputs'])
74-
time.sleep(0.25)
74+
time.sleep(0.1)
7575
self.connected = True
7676

77-
7877
def qxafs_connect_counters(self):
7978
self.counters = []
8079
time.sleep(0.1)
@@ -203,20 +202,22 @@ def get_state(self):
203202
val = self.scandb.get_info(key='qxafs_running', default=0)
204203
return int(val)
205204

206-
def get_lastupdate():
205+
def get_lastupdate(self):
207206
if self.heartbeat_pv is not None:
208207
return int(self.heartbeat_pv.get(as_string=True))
209208
return -1
210209

211-
def kill_old_process():
210+
def kill_old_process(self):
211+
print("kill old ", self.heartbeat_pv)
212212
if self.heartbeat_pv is not None:
213-
self.heartbeat_pv.put(-1)
213+
self.heartbeat_pv.put("-1")
214214

215215
pid = None
216216
with open(self.pidfile) as fh:
217217
pid = int(fh.readlines()[0][:-1])
218+
218219
if pid is not None:
219-
print(' killing pid=', pid, ' at ', time.ctime())
220+
print('killing pid=', pid, ' at ', time.ctime())
220221
os.system("kill -9 %d" % pid)
221222
time.sleep(1.0)
222223

@@ -238,57 +239,4 @@ def mainloop(self):
238239
time.sleep(1.0)
239240
if self.heartbeat_pv is not None:
240241
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

Comments
 (0)