-
Notifications
You must be signed in to change notification settings - Fork 277
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
Error when using bleak with kivy #176
Comments
This does not seem to be a bleak error, given that the error seems to originate from I recommend writing your bleak app first and then integrating it with your kivy app once you know both are working. |
Yes, it works if I comment the bleak import |
Then write the bleak app you want without kivy and I can advise you on that and then we can see if the problem is bleak or in integrating with kivy. |
Ok, thanks The app below subscribes to a gatt notification, wait 5sec and then finish the ble coroutine. It is done in a thread to run in parallel with kivy app. This code is working in windows 10 and ubuntu If I add the kivy app it works in ubuntu, but not windows. Under windows 10 anytime I import at the same time kivy and bleak it throws the previous error import asyncio
import threading
from bleak import BleakClient
address = "C8:FD:19:0E:F0:A6"
uuid = "0000ffe1-0000-1000-8000-00805f9b34fb"
def notification_handler(sender, data):
print("{}:{}".format(sender, data))
async def ble(address, loop):
print('start ble coroutine')
async with BleakClient(address, loop=loop) as client:
await client.start_notify(uuid, notification_handler)
global event
await event.wait()
await client.stop_notify(uuid)
print('finish ble coroutine')
async def finish(delay, loop):
print('start finish coroutine')
global event
await asyncio.sleep(delay, loop)
event.set()
print('end finish coroutine')
def do_ble(loop):
print('start thread ble')
loop.create_task(finish(5, loop))
loop.run_until_complete(ble(address, loop))
loop.close()
print('finish thread ble')
print('start app')
loop = asyncio.get_event_loop()
event = asyncio.Event()
thread_ble = threading.Thread(name='thread_ble', target=do_ble, args=(loop,), daemon=True)
thread_ble.start()
while True:
pass
print('finish app') |
This uses Try something like import asyncio
import threading
from bleak import BleakClient
address = "C8:FD:19:0E:F0:A6"
uuid = "0000ffe1-0000-1000-8000-00805f9b34fb"
def notification_handler(sender, data):
print("{}:{}".format(sender, data))
async def ble(address, event, loop):
print("start ble coroutine")
async with BleakClient(address, loop=loop) as client:
print("connected")
loop.create_task(finish(5, event, loop))
await client.start_notify(uuid, notification_handler)
await event.wait()
await client.stop_notify(uuid)
print("finish ble coroutine")
async def finish(delay, event, loop):
print("start finish coroutine")
await asyncio.sleep(delay, loop)
event.set()
print("end finish coroutine")
if __name__ == "__main__":
print("start app")
loop = asyncio.get_event_loop()
print("start thread ble")
event = asyncio.Event()
loop.run_until_complete(ble(address, event, loop))
loop.close()
print("finish thread ble") instead. Your |
Closing this since it does not seem to be a direct bug or issue wih bleak. |
Henrik: I rediscovered this error when attempting to combine bleak and kivy. Example Code The below code works fine
TypeError: import() takes at least 1 argument (0 given) is thrown when bleak is imported
|
Description
I'm trying to use bleak with kivy
What I Did
I've develop an app in kivy which subscribes to a ble service. This is working under Ubuntu 18.10 and Python 3.7
Under windows 10 I can't even import the bleak module. The kivy app is not created
The following code throws an error:
The error:
Other python modules:
The text was updated successfully, but these errors were encountered: