Skip to content

Executing example script fails after picking die. #2

@eruvanos

Description

@eruvanos

Problem

Executing the main.py the script fails after picking a die index.

Environment

M1-Mac: MacOS 13.1
Python: 3.11

Output

Scanning for GoDice devices...
Index: 0 - Die: 9F28E078-7CBE-ABBE-006E-AE0F35E68908: GoDice_8A8272_K_v04
Enter the index to connect to or press enter to connect to all available dice:
0
Exception in thread Thread-1 (init_die):
Traceback (most recent call last):
  File "/Users/xxx/.pyenv/versions/3.11.0/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/Users/xxx/.pyenv/versions/3.11.0/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/xxx/workspace-maic/godice/GoDicePythonAPI/godice.py", line 228, in init_die
    asyncio.run(self._die_loop())
  File "/Users/xxx/.pyenv/versions/3.11.0/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/xxx/.pyenv/versions/3.11.0/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/.pyenv/versions/3.11.0/lib/python3.11/asyncio/base_events.py", line 650, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/xxx/workspace-maic/godice/GoDicePythonAPI/godice.py", line 235, in _die_loop
    async with BleakClient(self.device) as self.client:
  File "/Users/xxx/.local/share/virtualenvs/godice-bfPtIbBb/lib/python3.11/site-packages/bleak/__init__.py", line 433, in __aenter__
    await self.connect()
  File "/Users/xxx/.local/share/virtualenvs/godice-bfPtIbBb/lib/python3.11/site-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/.local/share/virtualenvs/godice-bfPtIbBb/lib/python3.11/site-packages/bleak/backends/corebluetooth/client.py", line 116, in connect
    await manager.connect(self._peripheral, disconnect_callback, timeout=timeout)
  File "/Users/xxx/.local/share/virtualenvs/godice-bfPtIbBb/lib/python3.11/site-packages/bleak/backends/corebluetooth/CentralManagerDelegate.py", line 160, in connect
    await future
RuntimeError: Task <Task pending name='Task-4' coro=<GoDice._die_loop() running at /Users/xxx/workspace-maic/godice/GoDicePythonAPI/godice.py:235> cb=[_run_until_complete_cb() at /Users/xxx/.pyenv/versions/3.11.0/lib/python3.11/asyncio/base_events.py:180]> got Future <Future pending> attached to a different loop
2023-01-09 22:05:21.786 python[78506:2078117] PyObjC: Converting exception to Objective-C:
Traceback (most recent call last):
  File "/Users/xxx/.local/share/virtualenvs/godice-bfPtIbBb/lib/python3.11/site-packages/bleak/backends/corebluetooth/CentralManagerDelegate.py", line 293, in centralManager_didConnectPeripheral_
    self.event_loop.call_soon_threadsafe(
  File "/Users/xxx/.pyenv/versions/3.11.0/lib/python3.11/asyncio/base_events.py", line 803, in call_soon_threadsafe
    self._check_closed()
  File "/Users/xxx/.pyenv/versions/3.11.0/lib/python3.11/asyncio/base_events.py", line 519, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
2023-01-09 22:05:21.786 python[78506:2078117] *** Terminating app due to uncaught exception 'OC_PythonException', reason: '<class 'RuntimeError'>: Event loop is closed'
*** First throw call stack:
(
	0   CoreFoundation                      0x00000001b27633f8 __exceptionPreprocess + 176
	1   libobjc.A.dylib                     0x00000001b22aeea8 objc_exception_throw + 60
	2   _objc.cpython-311-darwin.so         0x000000010627ee98 PyObjCUtil_Strdup + 0
	3   _objc.cpython-311-darwin.so         0x000000010625f8d8 method_stub + 5856
	4   libffi.dylib                        0x00000001c1582f40 ffi_closure_SYSV_inner + 816
	5   libffi.dylib                        0x00000001c157a1e8 ffi_closure_SYSV + 56
	6   CoreBluetooth                       0x00000001c4ebbe60 -[CBCentralManager handlePeripheralConnectionCompleted:] + 524
	7   CoreBluetooth                       0x00000001c4ebdc28 -[CBCentralManager handleMsg:args:] + 244
	8   CoreBluetooth                       0x00000001c4ead478 -[CBManager xpcConnectionDidReceiveMsg:args:] + 192
	9   CoreBluetooth                       0x00000001c4ead370 __30-[CBXpcConnection _handleMsg:]_block_invoke + 52
	10  libdispatch.dylib                   0x00000001b24809dc _dispatch_call_block_and_release + 32
	11  libdispatch.dylib                   0x00000001b2482504 _dispatch_client_callout + 20
	12  libdispatch.dylib                   0x00000001b2489bbc _dispatch_lane_serial_drain + 672
	13  libdispatch.dylib                   0x00000001b248a73c _dispatch_lane_invoke + 436
	14  libdispatch.dylib                   0x00000001b2489a94 _dispatch_lane_serial_drain + 376
	15  libdispatch.dylib                   0x00000001b248a708 _dispatch_lane_invoke + 384
	16  libdispatch.dylib                   0x00000001b249534c _dispatch_workloop_worker_thread + 652
	17  libsystem_pthread.dylib             0x00000001b2605100 _pthread_wqthread + 288
	18  libsystem_pthread.dylib             0x00000001b2603e20 start_wqthread + 8
)
libc++abi: terminating with uncaught exception of type NSException

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Additional details

Following code runs without problems:

from GoDicePythonAPI.godice import create_dice

address = "9F28E078-7CBE-ABBE-006E-AE0F35E68908"  # address of my die

SERVICE_ID = "6e400001-b5a3-f393-e0a9-e50e24dcca9e"

die = create_dice(address)

die.pulse_led(5, 30, 5, (255, 0, 0))
die.send_battery_request()

while True:
    print(die.result_queue.get())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions