sccn / labstreaminglayer

LabStreamingLayer super repository comprising submodules for LSL and associated apps.
Other
522 stars 157 forks source link

Question: What issue occurs when PyLSL is not used from the main thread? #74

Open Morgan243 opened 3 years ago

Morgan243 commented 3 years ago

Hello LSL Devs,

First, thanks for the hard work on a great library! You are simplifying a lot challenging aspects in this space.

I'm developing some code to help support development of models/analysis that run against LSL streams. However, I noted the following in your README - can someone please expand on this line:

On Linux one currently cannot call pylsl functions from a thread that is not the main thread.

I'm using threading.Timer() to push data at certain times and have not noticed any issues, though my validation has been limited.

I'm not exactly sure if Python is launching a thread behind the scenes, or if it's just not doing it in a way that breaks LSL, or perhaps it is breaking LSL and I have not noticed data quality issues yet.

So what issues am I expected to have? Does it cause undefined behavior somewhere?

Again, thanks for your time!

cboulay commented 3 years ago

If I recall correctly, you'd get a segfault when calling pylsl's liblsl functions.

That note has been there a long time, probably since Python 2.6, and probably Ubuntu 16 or older. Obviously you have newer Python, its packages, and system libraries, and liblsl has been updated as well. 1.15 is out, available on conda-forge or from the liblsl release page. We haven't cut a new pylsl release. We'll do that soon.

I can't remember the actual source of the segaults, and I can't remember if it was all functions or only some, so it's hard to know if the problem has fixed. I wouldn't bet on it being fixed, but if you can run all of the functions that you need in a thread then I wouldn't expect any undefined behaviour.