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  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: pyepics problem with PV.put(wait=True)
From: Matt Newville <[email protected]>
To: Jameson Graef Rollins <[email protected]>
Cc: EPICS tech-talk <[email protected]>
Date: Thu, 14 Aug 2014 21:07:20 -0500
Hi Jameson,

On Thu, Aug 14, 2014 at 7:18 PM, Jameson Graef Rollins <[email protected]> wrote:
Hi, folks.  I'm seeing what might be a bug in the behavior of PVs in the
pyepics interface, or at the very least something inconsistent with
advertised behavior.

I'm trying to use the wait=True option to PV.put() to wait for process
completion, after which I want to log the put action.  Here's a basic
example:

#!/usr/bin/env python
>From epics import PV
pv = PV('T1:TEST-SYS_B')
for i in range(10):
    pv.put(i, wait=True)
    print pv.get()

However, what I'm consistently getting as output from the above is
something like the following:

0.0
0.0
2.0
3.0
3.0
4.0
6.0
6.0
8.0
9.0

Note that the output is not at all what is expected: on three out of ten
writes a pv.get() immediately following a pv.put(wait=True) fails to
return the newly updated value.  I see the same failures if I instead
set use_complete=True and check for put_complete==True before issuing
pv.get().

If the put() has actually completed, why is the get() still seeing the
old value?

Thanks in advance for any help or suggestions.

jamie.

Sorry for the trouble.  The basic issue here is that PV.get() relies (by default) on a callback on the monitored value to keep the PV's value up-to-date, avoiding explicit calls to ca.get().    The put(wait=True) or put-with-callback uses a *different* callback on the put() request.    When the put-callback completes, the callback for the monitored value may not have been run.

It's reasonable to say that when the put-with-wait completes that the cached value  should be updated.  I'll look into that. 

There are two potential solutions with the current behavior.   First, you can add a short wait after the put() to allow the monitored value to update, perhaps as:
    for i in range(10):
        pv.put(i, wait=True)
        time.sleep(0.001)
        print pv.get()

You could replace time.sleep() with epics.poll().   The danger with this approach is that it will add a slight delay, and doesn't actually guarantee that pv.get() will have the latest value.  But it will probably work, at least more often.

The alternative is to:
    for i in range(10):
        pv.put(i, wait=True)
        print pv.get(auto_monitor=False)

which will make an explicit call to ca.get() every time, not relying on the monitored value.   That will add a potential delay, but is probably the safest way to ensure that the value is the current one.

Does that work for you?

--Matt Newville

Replies:
Re: pyepics problem with PV.put(wait=True) Jameson Graef Rollins
References:
pyepics problem with PV.put(wait=True) Jameson Graef Rollins

Navigate by Date:
Prev: RE: pyepics problem with PV.put(wait=True) Mark Rivers
Next: Web OPI Xinyu.Wu
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: pyepics problem with PV.put(wait=True) Mooney, Tim M.
Next: Re: pyepics problem with PV.put(wait=True) Jameson Graef Rollins
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 17 Dec 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·