Skip to content
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

bleak.exc.BleakDBusError: [org.bluez.Error.InProgress] Operation already in progress is occur. #1036

Closed
KukhoHeo opened this issue Sep 28, 2022 · 4 comments · Fixed by #1369
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend

Comments

@KukhoHeo
Copy link

KukhoHeo commented Sep 28, 2022

  • bleak version: 0.18.1
  • Python version:3.10.6
  • Operating System: Ubuntu 22.04.1 LTS (Raspberry 4b)
  • BlueZ version (bluetoothctl -v) in case of Linux: 5.64

Description

when I do the program, the error occur.

import asyncio
import os
from bleak import *
import time

CHAR_UUID="4eab0101-0001-0001-0003-1001200252b9"

def notify_callback(sender, data):
    print(sender, data)

def disconnected_callback(client):
    print(f'Device {client.address} disconnected')

async def work( address):
    async with BleakClient(address) as client:
        client.set_disconnected_callback(disconnected_callback)
        await client.start_notify(CHAR_UUID, notify_callback)
    print(f'Work task for {address} end')

async def main():
    task_list=[]
    target_devices=["E2:A5:A4:C3:4C:C0","DC:8B:F0:17:5C:5A"]
    await asyncio.gather(work(target_devices[0]),work(target_devices[1]))
    print("Main task end")

if __name__ == "__main__":
    asyncio.run(main())

this is my simple program that connects two device in same time.

what should I do for fix the program?

@manschwetus
Copy link

I had this problem with pybricksdev, it seems that it was the adapter, once I disabled and enabled it, this started working.

@dlech
Copy link
Collaborator

dlech commented Sep 28, 2022

Connecting to two devices at the same time is problematic for many people. Try connecting to one first and then the other.

@dlech dlech added the Backend: BlueZ Issues and PRs relating to the BlueZ backend label Sep 29, 2022
@Amar-Judo
Copy link

I have this same issue, do you know the solution to solve this issue?
I am so much struggling to solve.

Many Thanks

Screenshot from 2022-12-31 00-54-01

@buganini
Copy link

bleak version: 0.20.2
Python version: 3.10.6
Operating System: Ubuntu 22.04.2 LTS (x64)
BlueZ version (bluetoothctl -v) in case of Linux: 5.64

I got the same error, stop scanner before connect and start scanner later works for me.

@dlech dlech closed this as completed Jul 19, 2023
dlech added a commit that referenced this issue Jul 19, 2023
This fixes several issues with the implementation. Notably, on Linux
trying to scan and connect to two devices at the same time results in:

    bleak.exc.BleakDBusError: [org.bluez.Error.InProgress] Operation already in progress

This is worked around by using an asyncio.Lock to ensure only one scan
and connect is called at a time.

Fixes: #1036

Also fixes error due to main() not being a coroutine:

    ValueError: a coroutine was expected, got <_GatheringFuture pending>

Fixes: #1288

Finally, command line args are added to make it easy to run the example
without modifying the code.
dlech added a commit that referenced this issue Jul 20, 2023
This fixes several issues with the implementation. Notably, on Linux
trying to scan and connect to two devices at the same time results in:

    bleak.exc.BleakDBusError: [org.bluez.Error.InProgress] Operation already in progress

This is worked around by using an asyncio.Lock to ensure only one scan
and connect is called at a time.

Fixes: #1036

Also fixes error due to main() not being a coroutine:

    ValueError: a coroutine was expected, got <_GatheringFuture pending>

Fixes: #1288

Finally, command line args are added to make it easy to run the example
without modifying the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants