| 1 | import mantid | 
|---|
| 2 | from mantid.simpleapi import StartLiveData | 
|---|
| 3 | import time | 
|---|
| 4 |  | 
|---|
| 5 | ######################### Time based cancellation ##################################################### | 
|---|
| 6 | print | 
|---|
| 7 | print "Starting time-based live event cancellation demo" | 
|---|
| 8 | print | 
|---|
| 9 |  | 
|---|
| 10 | MAX_MONITOR_TIME = 10 # in seconds | 
|---|
| 11 |  | 
|---|
| 12 | output_ws, last_timestamp, monitor_live = StartLiveData(UpdateEvery='5', Instrument='FakeEventDataListener', | 
|---|
| 13 | OutputWorkspace='ws') | 
|---|
| 14 | if 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 ######################################### | 
|---|
| 24 | print "-"*80 | 
|---|
| 25 | print | 
|---|
| 26 | print "Starting number of events-based live event cancellation demo" | 
|---|
| 27 | print | 
|---|
| 28 |  | 
|---|
| 29 | MAX_NUMBER_EVENTS = 2000 | 
|---|
| 30 |  | 
|---|
| 31 | output_ws, last_timestamp, monitor_live = StartLiveData(UpdateEvery='5',Instrument='FakeEventDataListener', | 
|---|
| 32 | PreserveEvents='1', OutputWorkspace='ws') | 
|---|
| 33 | if 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() | 
|---|