-
Notifications
You must be signed in to change notification settings - Fork 59
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
access violation reading 0xFFFFFFFFFFFFFFFF #29
Comments
pylsl isn't great at threading. This is a known issue in Linux. I didn't think it was a problem in Windows but I guess I'm not surprised to see that it is. An annoying workaround is to use a single thread to poll all the streams then to push data (e.g. via shared memory) to the other threads. Probably a better design is to use unique processes (not threads) to do as much independent parallel work as possible until the processed data have to be joined, at which point you could use shared mem or another IPC to get them together. While it's annoying this doesn't work, and I would welcome this being fixed, I have to admit that fixing pylsl in threads is fairly low priority. Due to the GIL there is barely any benefit to using threads in Python. If I have something I want to do in parallel without locking up the |
Can you share a little bit more of your code, e.g. the read_stream module? |
@cboulay the problem with using a single thread for multiple streams is that it introduces a lot of latency because it has to successfully pull in a sample from one stream before it can go onto the next, which completely locks up everything in case you have a marker stream you're pulling from. I guess I could try giving multiprocessing a shot instead. |
|
Hello, If it helps, I was also having issues with multiple threads on python, but only when I was trying to access inlet's info. I think the issues comes from how XML is handled internally by liblsl. I managed to find a workaround by parsing it manually, e.g.:
(tested with python 2, run on python 3 but I did not try to reproduce the original problem) Beside that I never had any troubles with multi-threading and LSL, that I have been using heavily :) edit: I don't remember the error I got but I think it was also a weird "access violation", always a shock wihen dealing with python :D |
The preferred approach would be
Interesting, is there any chance you could put together an MWE I could test against? |
Me neither. That's why i'm wondering. But in my code, i also convert the whole info to a dict before further accessing it, too. I'l assume you implemented the multithreading similar as follows? t = threading.Thread(target=read_stream, args=(stream_type))
t.start() The error probably stems, as @jfrey-xx suggested from the info structure being accessed in a loop, considering it has a state due to |
@tstenner seems like a hacky approach which would still introduce unnecessary latency.
@agricolab that is correct. |
Something like def read_stream(stream_type, lock):
streams = resolve_stream('type', stream_type)
inlet = StreamInlet(streams[0])
ch_labels = []
with lock:
ch = inlet.info().desc().child("channels").child("channel" )
for k in range(inlet.info().channel_count()):
ch_labels.append(ch.child_value("label"))
ch = ch.next_sibling()
csv_file = open(f'{stream_type}.csv', 'w', newline='')
with csv_file:
writer = csv.writer(csv_file)
writer.writerow(["Timestamp"] + ch_labels)
while True:
sample, timestamp = inlet.pull_sample()
csv_sample = [timestamp] + sample
writer.writerow(csv_sample)
sample_dict = OrderedDict(zip(ch_labels, sample))
print(stream_type, timestamp, sample_dict) https://docs.python.org/3/library/threading.html#with-locks On a side note: If you only pull single samples, but print and write to file every time, this might be slower than new samples coming in. You might want to switch to chunks or fill a buffer instead, unless your sampling rate is very slow. |
@agricolab I guess that might do it.
I was aware of this and am going to rewrite it in the near future but thanks anyways. |
Does |
Yes. Just tested it. Even if one of the outlets is killed, receiving the others will not be blocked. |
@jdevoldere , were you able to solve your issue, so it can be closed? |
@agricolab , would you be willing to update https://github.com/labstreaminglayer/liblsl-Python/blob/master/README.md#known-issues to specify the problem with accessing info in a thread? After that then I think we can close this issue. |
Sure, i just found the time to test again pulling from different threads with Python 3.7.6. on Pylsl 1.14 with
and it worked smoothly. @cboulay I can test whether the error with accessing the info stems from unlocked calls from different threads, that'll take longer to evaluate. |
accesses the XML in a locked fashion, and runs smoothly (on my machine) |
Happens sporadically so I'm not sure how to reproduce it but I'm reading multiple streams, one stream per thread.
The text was updated successfully, but these errors were encountered: