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  <20192020  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  <20192020 
<== Date ==> <== Thread ==>

Subject: Re: Many PV connections from CA client
From: Matt Newville via Tech-talk <tech-talk@aps.anl.gov>
To: Tong Zhang <zhangt@frib.msu.edu>
Cc: "tech-talk@aps.anl.gov" <tech-talk@aps.anl.gov>
Date: Thu, 21 Mar 2019 12:06:55 -0500
Hi Tong,

On Thu, Mar 21, 2019 at 10:05 AM Tong Zhang via Tech-talk <tech-talk@aps.anl.gov> wrote:
Hello,

As you can see from the attached screenshot, the warning messages from
ca module of pyepics happened when I was doing tasks described as below:

1. I created many epics.PV objects (few hundreds to a thousand);
2. Capture all the readings from these created PV objects in a for loop.

It looks like I can use caget_many(<PV list>) to achieve the goals, but
the whole logic needs to be well refactored, so what if I want do this
in the for-loop way, how can I avoid this UserWarnings, anyone can help
me understand this issue?

Those warning messages are coming because those PVs are not connected, or have not connected yet.   There are several possible reasons for that, including an IOC that is currently down or slow to respond.  It might work to add a short wait before fetching values, and it might be useful to test whether PVs are actually connected.

It's a little hard for me to tell what you're doing, but it should definitely be possible to create several hundred PVs and capture all those values in a loop.  Perhaps something like this:

     import epics
     import time
     # create some PVs
     pvs = []
     for i in range(1000, 1200):
           pvs.append(epics.get_pv('XXX:RFC_%d:E_RD_CAVS' % i)
     
     # wait for a brief time, to give a chance for connections to happen
     time.sleep(0.05)

     # read out the PV values 
     for step in range(10):
           # read a dict of {PVname:Value} 
           # version 1:  if you are pretty sure all PVs are connected
           result = {pv.pvname: pv.value for pv in pvs}   

           # version 2: if you are not confident that pvs are connected:
           result = {}
           for pv in pvs:
                if pv.connected: 
                     result[pv.pvname] = pv.value
                else: 
                     result[pv.pvname] = '<not connected>'

           # do something useful with the results
           print(results)
           time.sleep(1.0)


The recommended use is to create all the PVs once, as this will establish an Epics Channel that is internally, asynchronously monitored for changes, and then subsequent calls to PV.get() will report the latest value.
    
FWIW, `caget_many()` is designed especially for the use-case of wanting to get values for a very large number of PVs but *not* retain the Channel connections.   That's really good for a script that runs to collect data on many PVs and then exists (as one might do in a cron job).  But if the script or application is long-running and wants to have access to those PVs during the entire lifetime of the application, it is better to create and use a single PV per channel name.

Hope that helps.  If not, maybe you can give a little more detail on what you're doing,

--Matt


References:
Many PV connections from CA client Tong Zhang via Tech-talk

Navigate by Date:
Prev: RE: about Newport AG-UC module Mark Rivers via Tech-talk
Next: RE: about Newport AG-UC module [SEC=UNCLASSIFIED] POZAR, Andraz 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  <20192020 
Navigate by Thread:
Prev: Many PV connections from CA client Tong Zhang via Tech-talk
Next: RE: about Newport AG-UC module [SEC=UNCLASSIFIED] POZAR, Andraz 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  <20192020 
ANJ, 21 Mar 2019 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·