I'm working on getting PyEpics and Python threads to work together. I get a lot of
inconsistent behaviour, but the following seems to be somewhat consistent. At least
today it is. I have a motor record, 'L3:m1' and run the following:
from threading import Thread
import epics
import random
def th(pv, sp):
epics.ca.context_create()
pv.put(sp, wait=True)
epics.ca.context_destroy()
if __name__ == '__main__':
d1=random.randrange(360)
m = epics.PV('L3:m1')
t1 = Thread(target=th, args=(m, d1))
t1.start()
When executing the 'pv.put' statement, this (almost) always sits for about 30 seconds
doing nothing, and then moves the motor correctly. Why the 30 second delay?
However, the following program usually (though not always) executes correctly
without the 30 second delay.
from threading import Thread
import epics
import random
def th(pv, sp):
epics.ca.context_create()
pv.put(sp, wait=True)
epics.ca.context_destroy()
if __name__ == '__main__':
d1=random.randrange(360)
m = epics.PV('L3:m1')
t1 = Thread(target=th, args=(m, d1))
anyPV = epics.PV('L3:scan1')
t1.start()
The only difference is I created some arbitrary unrelated PV before starting the thread. I'm still
trying to understand CA contexts, so I'm not sure those calls are necessary, but
for some things I tried they seemed to be required. Other little changes, such as creating the
PV object inside the thread rather than passing it in to the thread, also seem to eliminate the 30 second delay.
Trying on my PC rather than linux co-hosted with IOC gives about a 10 second delay.
Any help or explanations are well appreciated.
Mark
Mark Vigder
Canadian Neutron Beam Centre
|