EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

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  <20212022  2023  2024  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  <20212022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Incompatibility of pyepics and pvaPy 4.0.0 on Windows
From: Matt Newville via Tech-talk <tech-talk at aps.anl.gov>
To: "Johnson, Andrew N." <anj at anl.gov>
Cc: EPICS tech-talk <tech-talk at aps.anl.gov>, "Veseli, Sinisa" <sveseli at anl.gov>, "De Carlo, Francesco" <decarlo at anl.gov>, "Nikitin, Viktor" <vnikitin at anl.gov>
Date: Fri, 10 Sep 2021 10:05:47 -0500
Hi Andrew, 

On Thu, Sep 9, 2021 at 7:08 PM Johnson, Andrew N. via Tech-talk <tech-talk at aps.anl.gov> wrote:
It occurred to me later that the situation I was thinking about should only occur if the code was using the CA Provider through the pvaccess API, which is unlikely to be the case here, the code is using pyepics for CA channels and pvapy for PVA channels. However I do think that the access fault you’re seeing is because a thread that is calling libca doesn’t have a CA context.

On Sep 9, 2021, at 5:16 PM, Mark Rivers <rivers at cars.uchicago.edu> wrote:

Ø  That could mean that calling pyepics code from inside a pvaccess callback/notification routine might no longer work if pyepics doesn’t properly set its CA context before calling routines inside libca (unfortunately that’s probably what’s happening, given the access violation that Mark is seeing).
 
The pyepics call that it crashing is not happening inside a pvaccess callback/notification routine, it is happening in the following code:
 
class TomoScan():
    def __init__(self, pv_files, macros):
        # Start the watchdog timer thread
        thread = threading.Thread(target=self.reset_watchdog, args=(), daemon=True)
        thread.start()
    def reset_watchdog(self):
        """Sets the watchdog timer to 5 every 3 seconds"""
        while True:
            self.epics_pvs['Watchdog'].put(5)
            time.sleep(3)
 
So the tomoscan constructor is creating a new thread with threading.Thread.  That thread is running the simple reset_watchdog function, which simply does an epics.PV.put(5) every 3 seconds.  That call crashes with pvaccess 4.0.0 under the following conditions:
-          tomoscan is built with the functions that include pvaccess
or
-          tomoscan is built without pvaccess but PYEPICS_LIBCA is pointing to the version of ca.dll that comes with pvaccess

Does pyepics give access to the libca routines ca_current_context() and ca_attach_context() ? If so I would recommend having that watchdog thread explicitly attach to the context that was created for the main thread. I think that will probably solve the problem if those APIs are available.


Yes, those are available.  There is also a simple subclass of threading.Thread (epics.ca.CAThread) that explicitly attaches the thread to the initial CA context.  My recollection was that Mark tried this and it didn't help.  

--Matt


Replies:
Re: Incompatibility of pyepics and pvaPy 4.0.0 on Windows Johnson, Andrew N. via Tech-talk
References:
Incompatibility of pyepics and pvaPy 4.0.0 on Windows Mark Rivers via Tech-talk
Re: Incompatibility of pyepics and pvaPy 4.0.0 on Windows Veseli, Sinisa via Tech-talk
Re: Incompatibility of pyepics and pvaPy 4.0.0 on Windows Johnson, Andrew N. via Tech-talk
RE: Incompatibility of pyepics and pvaPy 4.0.0 on Windows Mark Rivers via Tech-talk
Re: Incompatibility of pyepics and pvaPy 4.0.0 on Windows Johnson, Andrew N. via Tech-talk

Navigate by Date:
Prev: Re: Cannot build StreamDevice on Windows 64bit Johnson, Andrew N. via Tech-talk
Next: Re: Cannot build StreamDevice on Windows 64bit Heinz Junkes via Tech-talk
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  <20212022  2023  2024 
Navigate by Thread:
Prev: Re: Incompatibility of pyepics and pvaPy 4.0.0 on Windows Johnson, Andrew N. via Tech-talk
Next: Re: Incompatibility of pyepics and pvaPy 4.0.0 on Windows Johnson, Andrew N. via Tech-talk
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  <20212022  2023  2024 
ANJ, 10 Sep 2021 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·