-
Notifications
You must be signed in to change notification settings - Fork 38
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
Port to txaio? #35
Comments
Thanks for the suggestion. I hadn't come across txaio yet and it' certainly If you're up to the challenge, I'd happily accept patches on a Thanks for the patch :) Tom On Sun, May 29, 2016 at 4:01 PM, Mathieu Bridon [email protected]
|
Co-author of txaio here;) Using txaio, the txdbus library could be made working on Python 2.7+ for both Twisted and asyncio from one codebase. txdbus in its implementation would need to stick to:
Further, an internal protocol/factory abstraction is needed. Eg here is AutobahnPython, biggest txaio user:
Granted, this is a bit of a tricky design, but it achieves the goal of minimizing network framework specific code, maximize agnostic code, and all from a single code base. Also important to note: while the above approach puts some burden on the library implementor, the users of the library have maximum freedom and convenience. Eg it is no problem using the latest Python 3.6 co-routine goodies in app code on top of the library - the resulting app won't run on both Twisted/asyncio then of course, because the app code writer decided. Of course the app code itself could also be written without co-routines/chaining, and then it would run on both (eg allowing to switch framework from a command line option) - but I wouldn't recommend that for apps (only for libs). The code base seems to be mostly Python 3 compatible, which is great of course: ===============================================================================
[SKIPPED]
Not yet ported to python3
txdbus.test.test_authentication.ServerObjectTester.test_bad_command
txdbus.test.test_authentication.ServerObjectTester.test_bad_mech
txdbus.test.test_authentication.ServerObjectTester.test_bad_mech2
txdbus.test.test_authentication.ServerObjectTester.test_cancel
txdbus.test.test_authentication.ServerObjectTester.test_max_rejects
txdbus.test.test_authentication.ServerObjectTester.test_no_null_byte_at_start
txdbus.test.test_authentication.ServerObjectTester.test_reject
txdbus.test.test_authentication.ServerObjectTester.test_retry
txdbus.test.test_authentication.ServerObjectTester.test_too_long
-------------------------------------------------------------------------------
Ran 255 tests in 1.768s
PASSED (skips=9, successes=246)
(cpy361_7) oberstet@thinkpad-t430s:~/scm/3rdparty/txdbus$ |
In the meantime, you can use txdbus within an asyncio app using
|
You can also use txdbus as usual (with Deferred objects) within an asyncio loop:
|
@DurandA shared a few examples that are possible due to recent Twisted developments, allowing Twisted code to interoperate with asyncio code and vice-versa. Maybe the docs could include an "asyncio" integration section with these two examples and a link to Twisted's docs about it? |
Would you like to create a PR with these examples in the README? 🙂 |
Just so you know, I just stumbled over this (I guess somewhat experimental) pure-python dbus client implementation that claims to have support for blocking, asyncio & Tornado I/O1 by utilizing an I/O-free core2: It also has an high-level interface that is slightly more low-level that what import asyncio
from jeepney import DBusAddress, new_method_call
from jeepney.integrate.asyncio import connect_and_authenticate
notifications = DBusAddress('/org/freedesktop/Notifications',
bus_name='org.freedesktop.Notifications',
interface='org.freedesktop.Notifications')
async def send_notification():
(transport, protocol) = await connect_and_authenticate(bus='SESSION')
msg = new_method_call(notifications, 'Notify', 'susssasa{sv}i',
('jeepney_test', # App name
0, # Not replacing any previous notification
'', # Icon
'Hello, world!', # Summary
'This is an example notification from Jeepney',
[], {}, # Actions, hints
-1, # expire_timeout (-1 = default)
))
# Send the message and await the reply
reply = await protocol.send_message(msg)
print('Notification ID:', reply[0])
loop = asyncio.get_event_loop()
loop.run_until_complete(send_notification()) Building something like |
Note: opening a new issue to avoid polluting the other one, which is about Python 3 after all.
Over at #11 (comment), you mentioned you'd be interested in having txdbus work with both twisted and asyncio.
How about porting txdbus to txaio?
That would achieve compatibility with asyncio and twisted.
The text was updated successfully, but these errors were encountered: