labrad / pylabrad

python interface for labrad
52 stars 31 forks source link

Working with Datavault signals #187

Closed zibrov-zlobin closed 9 years ago

zibrov-zlobin commented 9 years ago

Hi, I am trying to understand how the signaling works based on the Datavault code. I've written a simple listener client (taken from https://github.com/labrad/pylabrad/wiki/Pylabrad-Signal-Slot-Example):

    @inlineCallbacks
    def connect(self):
        from labrad.wrappers import connectAsync
        cxn = yield connectAsync(name = 'Signal Widget')
        self.server = cxn.data_vault
        yield self.server.signal__new_dataset(self.ID)
        yield self.server.addListener(listener = self.displaySignal, 
                source = None, ID = self.ID) 

    def displaySignal(self, cntx, signal):
        print "Signal received "

and from a python shell:

 cxn = labrad.connect()
 dv   = cxn.data_vault()

If I create a new data set:

 dv.new('Data', ('x [v]', 'x2 [v]'), ('y [v]' , 'y2 [v]'))

Then I do get an output from the client, "Signal received is printed". But if I change the client to listen for yield self.server.signal__data_available(self.ID) which judging from the code should be emitted everytime data is added, the client does not respond to dv.add((1,2,3,4))

What am I missing? Thanks

maffoo commented 9 years ago

The data available signal is only sent to clients who have a particular dataset open for reading, so you'd need to call self.server.open(dataset) to start receiving signals about data being added to a particular dataset.

In addition, the server keeps track for each reader whether it has sent a signal, and whether you have fetched more data. Each client will only be sent one data available message between calling get to load more data, even if in that time multiple calls to add are made. This is just an optimization to avoid spamming clients with lots of messages, especially if they are reading slowly.

DanielSank commented 9 years ago

I just filed an issue about documenting the signals in the datavault server. Let's not close this issue until the documentation goes in.

zibrov-zlobin commented 9 years ago

Thanks a lot! Makes much more sense now

maffoo commented 9 years ago

Closing for now as this has been answered. See #254 where we are tracking actually adding this to the docs.