alexandrebarachant / muse-lsl

Python script to stream EEG data from the muse 2016 headset
BSD 3-Clause "New" or "Revised" License
616 stars 182 forks source link

MacOS Issue in 10.13.6 with muselsl #180

Closed iPsych closed 2 years ago

iPsych commented 2 years ago
Searching for Muses, this may take up to 10 seconds...
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/muselsl", line 11, in <module>
    load_entry_point('muselsl==2.2.0', 'console_scripts', 'muselsl')()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl-2.2.0-py3.7.egg/muselsl/__main__.py", line 57, in main
    cli = CLI(args.command)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl-2.2.0-py3.7.egg/muselsl/cli.py", line 9, in __init__
    getattr(self, command)()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl-2.2.0-py3.7.egg/muselsl/cli.py", line 32, in list
    list_muses(args.backend, args.interface)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl-2.2.0-py3.7.egg/muselsl/stream.py", line 51, in list_muses
    devices = adapter.scan(timeout=MUSE_SCAN_TIMEOUT)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl-2.2.0-py3.7.egg/muselsl/backends.py", line 33, in scan
    scanner = bleak.BleakScanner()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/bleak/backends/corebluetooth/scanner.py", line 44, in __init__
    self._manager = CentralManagerDelegate.alloc().init()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/bleak/backends/corebluetooth/CentralManagerDelegate.py", line 61, in init
    self.event_loop = asyncio.get_running_loop()
RuntimeError: no running event loop
objc[740]: CentralManagerDelegate object 0x7fcaa8ef4100 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug
Exception ignored in: <CentralManagerDelegate objective-c instance 0x0>
SystemError: <class 'objc.RevivedObjectiveCObjectWarning'> returned a result with an error set
Exception ignored in: <function CentralManagerDelegate.__del__ at 0x107966f80>

Above error happens when install muselsl==2.2.0 However it resolved with muselsl==2.1.0. Possible compatibility issue on it.

jdpigeon commented 2 years ago

Looks like an issue with the bleak backend. You should be able to cirumvent this issue by specifying a different backend with --backend. I think bgapi used to the recommended backend for OSX before we moved to bleak.

jdpigeon commented 2 years ago

@iPsych, @xloem, I don't have my muse with me while I'm on vacation. Would you mention testing to see if this change makes the library more reliable on Mac?

nolanrbrady commented 2 years ago

I'm getting the same error. After trying muselsl list -b bgapi I got the following:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/muselsl", line 11, in <module>
    load_entry_point('muselsl==2.2.0', 'console_scripts', 'muselsl')()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl/__main__.py", line 57, in main
    cli = CLI(args.command)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl/cli.py", line 9, in __init__
    getattr(self, command)()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl/cli.py", line 32, in list
    list_muses(args.backend, args.interface)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl/stream.py", line 59, in list_muses
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/muselsl/stream.py", line 49, in list_muses
    adapter.start()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygatt/backends/bgapi/bgapi.py", line 203, in start
    self._detect_device_port()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygatt/backends/bgapi/bgapi.py", line 147, in _detect_device_port
    raise BGAPIError("Unable to auto-detect BLED112 serial port")
pygatt.backends.bgapi.exceptions.BGAPIError: Unable to auto-detect BLED112 serial port

To be clear, I am not using a BLED112 but I was under the impression that since my computer supported BLE (2018 Macbook Pro running Big Sur version 11.6.6) I wouldn't need to use a BLED112. I might be mistaken though.

jdpigeon commented 2 years ago

That error makes sense. the BGAPI backend does required a BLED112 dongle.

Would you be able to test the changes in this PR (https://github.com/alexandrebarachant/muse-lsl/pull/181) and see if it allows you to connect with bleak? I'm at a bit of a loss since this seems to more of a bleak issue

nolanrbrady commented 2 years ago

I just checked it out. The pull request you submitted seems to fix it for me.

xloem commented 2 years ago

thanks so much for sorting this out

it looks like a new version of bleak runs asyncio code in the scanner constructor. the fix makes sense.