EPICS Home

Experimental Physics and Industrial Control System


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

Subject: Re: ca.py - Throws error - workaround
From: Matt Newville <[email protected]>
To: [email protected], EPICS Tech Talk <[email protected]>
Date: Thu, 14 Apr 2011 11:07:11 -0500
Hi Luca,

I hope it's OK with you that I'm sending the message to Tech-Talk,
where there are many people with much better understanding of Channel
Access than I have.

On Thu, Apr 14, 2011 at 1:58 AM, Luca Luisa <[email protected]> wrote:
> Hi,
> I'm working with PyEpics version 3.1.1.
> My QT Python application communicates with many EPICS servers where hundred
> of PVs are delivered.
>
> Our application has to deal with any EPICS server
> disconnection/re-connection that can happen during the application run.
>
> Each PV used by this QT Python application has a callback function added
> with the module "add_callback()".
>
> When I noticed an EPICS server disconnection, I clear the callbacks with the
> method "clear_callbacks()".
>
> When any EPICS server re-connect again, I try to add again another callback
> function to the same PV instance previously created, if fails (the
> add_callback returns None) I re-create the PV instance again and try to add
> the callback function.
>
> But in the cycle above described used to handle the dynamic connection to
> EPICS server, I get a lot of unknown errors in the terminal from where I
> launch my application, those are:
>
> -------------------------------------------------------------------------------
> TypeError: __on_connect() got an unexpected keyword argument 'count'
> Traceback (most recent call last):
>  File "_ctypes/callbacks.c", line 295, in 'calling callback function'
>  File "/usr/local/lib/python2.6/dist-packages/epics/ca.py", line 420, in
> _onGetEvent
>    args.usr(value=value, **kwds)
> -------------------------------------------------------------------------------
>
> Our application is very complex so I cannot send you an example.
>
> In order to remove this error that full-fills the terminal window, I had to
> change the "ca.py" source with a try: except: statement.
> The diff is:
>
> 419,423c419,420
> <     try:
> <     	if hasattr(args.usr, '__call__'):
> <         	args.usr(value=value, **kwds)
> <     except:
> < 	""""""
> ---
> >     if hasattr(args.usr, '__call__'):
> >         args.usr(value=value, **kwds)
>
> My solution is a pure workaround to make my application working and I got
> success but I would like to know if this is a known error or my way to
> handle connection/disconnection of a EPICS server is wrong.
>
> Many thanks
>
> Ing. Luca Luisa

I'm reluctant to make that change, as it's the only place ca.py can
tell the programmer that there was an error in running the
user-supplied callback and this change silences that message.

This message:

> TypeError: __on_connect() got an unexpected keyword argument 'count'
> Traceback (most recent call last):
>  File "_ctypes/callbacks.c", line 295, in 'calling callback function'
>  File "/usr/local/lib/python2.6/dist-packages/epics/ca.py", line 420, in
> _onGetEvent
>    args.usr(value=value, **kwds)

says that PV.__on_connect() -- the internally defined connection
callback for a PV -- is being run as a change-in-value callback.  I'm
not sure how that's even possible.

> When I noticed an EPICS server disconnection, I clear the callbacks with the
> method "clear_callbacks()".

I'm not sure this is necessary.  Have you tried not doing this?
Obviously, you won't get a callback from a disconnected PV, and will
get a callback upon reconnection, but I would think that's not worse
than explicitly clearing and re-setting callbacks.  I can verify that
it does works for me in simple test scripts to not clear "change
value" callbacks and restart the server IOC.

> When any EPICS server re-connect again, I try to add again another callback
> function to the same PV instance previously created, if fails (the
> add_callback returns None) I re-create the PV instance again and try to add
> the callback function.

For PV.add_callback() to return None, the PV has to be unconnected --
or at least that's the intention. So it's hard to understand what's
happening if you wait for reconnection to add a callback.  I do think
it shouldn't be necessary to re-create the PV.

I'm not sure whether this is related to using QT.  A minimal example
would be really helpful.

--Matt


Replies:
Re: ca.py - Throws error - workaround Tim Mooney
RE: ca.py - Throws error - workaround Jeff Hill

Navigate by Date:
Prev: Re: ioc segfault if - c seq flag is not set or +c? J. Lewis Muir
Next: Re: ca.py - Throws error - workaround Tim Mooney
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: RE: ioc segfault if - c seq flag is not set or +c? Abadie Lana
Next: Re: ca.py - Throws error - workaround Tim Mooney
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024