-
Notifications
You must be signed in to change notification settings - Fork 669
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
[WIP] Begin implementation of asynchronous transfers, Issue #63 #303
base: master
Are you sure you want to change the base?
Conversation
This function is not available as a library symbol, as it is inlined in libusb. It is extremely dangerous, and we must deal with it.
This function is not available as a library symbol, as it is inlined in libusb. It is extremely dangerous, and we must deal with it.
https://github.com/vpelletier/python-libusb1 |
This is a WIP to address #63. |
It seems benign, since transfers that complete earlier will have been | ||
marked as donem and not run libusb_handle_events(). However, is this a | ||
correct way to handle events? | ||
TODO 2: Is libusb_handle_events() really non-blocking? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope 😕 I tried to test on my receipt printer:
from escpos.printer import Usb
p = Usb(0x2730, 0x2002, None, 0, 0x81, 0x02)
print("#print text")
p.text(f"{'ПУТИН ХУЙЛО ' * 300}")
print("#print qr")
p.qr("All the things she said", size=16, model=2)
print("#cut")
p.cut(feed=False)
Changed the function to show execution time:
import time
while not self._fut.done():
st = time.time()
_check(_lib.libusb_handle_events(self._ctx))
print(round(time.time()-st, 5))
await asyncio.sleep(0.0001)
#print text
4e-05
0.00304
#print qr
2e-05
1.71189
1e-05
1e-05
#cut
2e-05
Not sure if anyone is working on this or not. I tend to think this is one major missing feature (along with hotplug). |
The purpose of these patches is to allow asynchronous USB transfers. Keep in mind that I am not claiming this should be the final form. I'm not an asyncio expert, and I am open for suggestions on how to improve the implementation. Note that async transfers are only imlemented for the libusb1 backend.
I am striving to achieve an API that looks like the following example:
Note that this is symmetrical to the sync functions, in that the transfer type does not have to be specified. It is derived from the endpoint.
await transfer.result() is similar to an asyncio.Future, although the implementation is not exactly an awaitable future. This is an implementation detail, and it could be changed if needed.