Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear_callbacks leaves connection and access callbacks alive #208

Closed
hhslepicka opened this issue Jun 22, 2020 · 2 comments · Fixed by #209
Closed

clear_callbacks leaves connection and access callbacks alive #208

hhslepicka opened this issue Jun 22, 2020 · 2 comments · Fixed by #209

Comments

@hhslepicka
Copy link
Contributor

Users reported some issues with PyDM recently that when IOCs are rebooted they get a message that connection and access control callbacks failed even if the widget was no longer at the screen.
I tracked it down and I was able to isolate the issue into an example:

Instructions to reproduce:

  • Run the code below...
  • When the code goes into the poll loop, kill the IOC
  • Note on the terminal that even with the PV disconnected the connection and access callbacks are invoked.

Note: Change the PV from MTEST:Float to something else that you have.

import epics
import time


def conn_callback(*args, **kwargs):
    print(f'{time.time()} conn_callback invoked with: {args} | {kwargs}')


def access_callback(*args, **kwargs):
    print(f'{time.time()} access_callback invoked with: {args} | {kwargs}')


print(f'{time.time()} - Create PV')
pv = epics.PV('MTEST:Float', connection_callback=conn_callback, access_callback=access_callback)

print(f'{time.time()} - Connect')
pv.connect()
print(f'{time.time()} - Wait For Connection')
pv.wait_for_connection()

print(f'{time.time()} - Invoke disconnect')
pv.disconnect()

print(f'{time.time()} - Lets enter on poll loop')
try:
    while True:
        epics.ca.poll()
except KeyboardInterrupt:
    print(f'{time.time()} - Poll loop terminated')
    pass

This produces the following output:

1592863195.09071 - Create PV
1592863195.111618 - Connect
1592863195.142028 access_callback invoked with: (True, True) | {'pv': <PV 'MTEST:Float': not connected>}
1592863195.142275 conn_callback invoked with: () | {'pvname': 'MTEST:Float', 'conn': True, 'pv': <PV 'MTEST:Float': not connected>}
1592863195.14254 - Wait For Connection
1592863195.1425579 - Invoke disconnect
1592863195.144663 - Lets enter on poll loop


CA.Client.Exception...............................................
    Warning: "Virtual circuit disconnect"
    Context: "10.0.0.211:5064"
    Source File: ../cac.cpp line 1237
    Current Time: Mon Jun 22 2020 15:00:04.489395534
..................................................................
1592863204.4895098 conn_callback invoked with: () | {'pvname': 'MTEST:Float', 'conn': False, 'pv': <PV 'MTEST:Float': not connected>}
1592863204.489681 access_callback invoked with: (False, False) | {'pv': <PV 'MTEST:Float': not connected>}

For now I can force clear the connection and access callbacks on my side.

I would like to pick your brain before submitting a PR as what would be the best fix for this case:

  • Add the cleaning routine at clear_callbacks to also clear the other two callbacks
  • Other alternatives?

Could this also be related to #156 ?

@newville
Copy link
Member

@hhslepicka What does "they get a message that connection and access control callbacks failed even if the widget was no longer at the screen" mean? What failed?

Just to be clear, is the problem that a disconnected PV still has active connection callback and access callbacks? I would guess that PV.disconnect() should probably remove the connection and access callbacks.

Other than that, everything else looks OK to me. But maybe I'm not understanding.

@hhslepicka
Copy link
Contributor Author

@newville the error message on our end is that the callback tries to access a widget which is no longer instantiated and that should never happen.

You are correct on the problem. disconnect should clear the calbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants