pylsl: access violation reading 0xFFFFFFFFFFFFFFFF

Exception in thread Thread-4:
Traceback (most recent call last):
  File "C:\Users\Gerbuiker\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\Gerbuiker\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:/Users/Gerbuiker/PycharmProjects/LabEnvironment/receive_data.py", line 14, in read_stream
    ch_labels.append(ch.child_value("label"))
  File "C:\Users\Gerbuiker\Documents\Virtualenvs\HITLab\lib\site-packages\pylsl\pylsl.py", line 985, in child_value
    res = lib.lsl_child_value_n(self.e, str.encode(name))
OSError: exception: access violation reading 0xFFFFFFFFFFFFFFFF

Happens sporadically so I’m not sure how to reproduce it but I’m reading multiple streams, one stream per thread.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

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.

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.:

import xml.etree.ElementTree as ET
root = ET.fromstring(inlet.info.as_xml())
var_value = root.find("desc").find("var").text

(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 😄