sccn / liblsl

C++ lsl library for multi-modal time-synched data transmission over the local network
Other
114 stars 67 forks source link

lib.lsl_open_stream does not block until the stream is fully ready #176

Open mscheltienne opened 1 year ago

mscheltienne commented 1 year ago

I discovered this using the Python API, but it's most likely present everywhere. See below the desription and a MWE in Python:

In the Python API, StreamInlet.open_stream(timeout) is not completely blocking. If you create an outlet, create an inlet, open the stream on the inlet and then immediately push. a sample and pull a sample (with a positive timeout to wait until a sample appears in the inlet), it will hang out for the duration of the timeout specified in pull_sample because the sample was pushed before the stream was completely open. At least that's my interpretation. Here is a MWE:

import time
from pylsl import StreamInfo, StreamInlet, StreamOutlet, resolve_streams
sinfo = StreamInfo("test", "", 1, 0.0, "string", "test-stream")
outlet = StreamOutlet(sinfo)
stream = resolve_streams(wait_time=2)[0]
inlet = StreamInlet(stream)
inlet.open_stream(timeout=1000)
time.sleep(0.1)  # comment to show the issue
outlet.push_sample("1")
data, ts = inlet.pull_sample(timeout=2)
assert len(data) == 1

With the sleep, data is received; without the sleep, inlet.pull_sample exit after 2 seconds and data is None .