Ticket #8971: test_live_cancel_same_script.py

File test_live_cancel_same_script.py, 1.5 KB (added by Martyn Gigg, 7 years ago)
Line 
1import mantid
2from mantid.simpleapi import StartLiveData
3import time
4
5######################### Time based cancellation #####################################################
6print
7print "Starting time-based live event cancellation demo"
8print
9
10MAX_MONITOR_TIME = 10 # in seconds
11
12output_ws, last_timestamp, monitor_live = StartLiveData(UpdateEvery='5', Instrument='FakeEventDataListener',
13                                                        OutputWorkspace='ws')
14if monitor_live:
15    start_time = time.time()
16    while (time.time() - start_time) < MAX_MONITOR_TIME:
17        time.sleep(0.5)
18    monitor_live.cancel() # it's a request so it's not immediate
19    while monitor_live.isRunning():
20        pass
21    print "\nTimeout reached, killed MonitorLiveData"
22
23######################### Number of events based cancellation #########################################
24print "-"*80
25print
26print "Starting number of events-based live event cancellation demo"
27print
28
29MAX_NUMBER_EVENTS = 2000
30
31output_ws, last_timestamp, monitor_live = StartLiveData(UpdateEvery='5',Instrument='FakeEventDataListener',
32                                                        PreserveEvents='1', OutputWorkspace='ws')
33if monitor_live:
34    while output_ws.getNumberEvents() < MAX_NUMBER_EVENTS:
35        time.sleep(0.5)
36    monitor_live.cancel()
37    print
38    print "Maximum number of events reached/succeeded, killed MonitorLiveData"
39    print "Total number of events recorded=%d" % output_ws.getNumberEvents()