This commit is contained in:
48
script/cpy/TestBlueskyPause.py
Normal file
48
script/cpy/TestBlueskyPause.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from functools import partial
|
||||
import threading
|
||||
import traceback
|
||||
import socket
|
||||
|
||||
CTRL_CMD_PORT = 9587
|
||||
msg=None
|
||||
if ("ctrl_cmd_socket" in globals()) and (ctrl_cmd_socket is not None):
|
||||
ctrl_cmd_socket.close()
|
||||
ctrl_cmd_task_thread.join(5.0)
|
||||
if ctrl_cmd_task_thread.is_alive():
|
||||
raise Exception("Cannot stop ctrl_cmd_task_thread")
|
||||
|
||||
def on_ctrl_cmd(cmd):
|
||||
global RE
|
||||
print ("Control command: ", cmd)
|
||||
if cmd=="abort":
|
||||
if "RE" in globals():
|
||||
if RE.state not in ['idle','paused', 'pausing']:
|
||||
print ("Run Engine pause request")
|
||||
RE.request_pause()
|
||||
|
||||
def ctlm_cmd_task(port,parent_thread, rc):
|
||||
try:
|
||||
global ctrl_cmd_socket
|
||||
print ("Starting control command task")
|
||||
quit=False
|
||||
with socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) as ctrl_cmd_socket:
|
||||
ctrl_cmd_socket.bind(("127.0.0.1", port))
|
||||
ctrl_cmd_socket.settimeout(2.0)
|
||||
while(quit==False) and (run_count==rc) and parent_thread.is_alive() and not ctrl_cmd_socket._closed:
|
||||
try:
|
||||
msg,add = ctrl_cmd_socket.recvfrom(100)
|
||||
except socket.timeout:
|
||||
continue
|
||||
cmd =msg.decode('UTF-8')
|
||||
on_ctrl_cmd(cmd)
|
||||
if cmd=="exit":
|
||||
quit=True
|
||||
ctrl_cmd_socket.sendto("ack".encode('UTF-8'), add)
|
||||
finally:
|
||||
print("Quitting control command task")
|
||||
|
||||
ctrl_cmd_task_thread = threading.Thread(target=partial(ctlm_cmd_task, CTRL_CMD_PORT, threading.currentThread(), run_count))
|
||||
ctrl_cmd_task_thread.setDaemon(True)
|
||||
ctrl_cmd_task_thread.start()
|
||||
|
||||
#RE(rel_scan(dets, motor, -1, 1, 10))
|
||||
Reference in New Issue
Block a user