1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 <2011> 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 | Index | 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 <2011> 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 |
<== Date ==> | <== Thread ==> |
---|
Subject: | PyEpics and Python threads |
From: | "Vigder, Mark" <[email protected]> |
To: | "[email protected]" <[email protected]> |
Date: | Wed, 20 Apr 2011 14:04:08 -0400 |
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
|