pvaPy icon indicating copy to clipboard operation
pvaPy copied to clipboard

occasional segfault when reinitializing channel that is subscribed to class member function

Open bsobhani opened this issue 1 year ago • 1 comments

In the following script, when I set use_class_cb to 1, the script segfaults, but when I set use_class_cb to 0 it does not segfault:

import pvaccess
import time


def func_cb(rec):
        monitor.class_cb(rec)
        return


class Monitor:
        def __init__(self):
                self.channel = None
        def class_cb(self, rec):
                return

monitor = Monitor()
use_class_cb = 1
pvname = "nes:neutrons"
while True:
        if monitor.channel is not None:
                monitor.channel.stopMonitor()
        monitor.channel = pvaccess.Channel(pvname)
        if use_class_cb == 1:
                # segfaults sometimes
                monitor.channel.subscribe("monitor_cb", monitor.class_cb)
        else:
                # does not segfault
                monitor.channel.subscribe("monitor_cb", func_cb)
        monitor.channel.startMonitor()
        time.sleep(1)

Note: On my setup, nes:neutrons is a PV that updates frequently (multiple times per second). If I point to this PV it crashes within a few seconds. I tried pointing it to a PV that updates less frequently (once per second), and it took longer to crash (a little less than an hour).

bsobhani avatar Nov 06 '24 20:11 bsobhani