Skip to content

Commit

Permalink
Support Python 3.11 (#1599)
Browse files Browse the repository at this point in the history
* Update asyncio examples to use new syntax

* python3.11 support in asyncio component
  • Loading branch information
om26er committed Oct 28, 2022
1 parent 201eeb2 commit 68dc8c6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
3 changes: 1 addition & 2 deletions autobahn/asyncio/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ def run(components, start_loop=True, log_level='info'):
# import signal
# signal.signal(signal.SIGINT, signal.SIG_DFL)

@asyncio.coroutine
def nicely_exit(signal):
async def nicely_exit(signal):
log.info("Shutting down due to {signal}", signal=signal)

try:
Expand Down
5 changes: 2 additions & 3 deletions examples/asyncio/wamp/component/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ def join(session, details):
"example.foo",
options=RegisterOptions(details_arg='details'),
)
@asyncio.coroutine
def foo(*args, **kw):
async def foo(*args, **kw):
print("foo({}, {})".format(args, kw))
for x in range(5, 0, -1):
print(" returning in {}".format(x))
yield from asyncio.sleep(1)
await asyncio.sleep(1)
print("returning '42'")
return 42

Expand Down
12 changes: 5 additions & 7 deletions examples/asyncio/wamp/component/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
from autobahn.asyncio.component import Component, run
from autobahn.wamp.types import RegisterOptions
from autobahn.wamp.exception import ApplicationError
import asyncio


@asyncio.coroutine
def main(reactor, session):
async def main(reactor, session):
print("Client session={}".format(session))

try:
res = yield from session.register(lambda: None, "com.foo.private")
res = await session.register(lambda: None, "com.foo.private")
print("\n\nregistering 'com.foo.private' should have failed\n\n")
except ApplicationError as e:
print("registering 'com.foo.private' failed as expected: {}".format(e.error))

res = yield from session.register(
res = await session.register(
lambda: None, "should.work",
options=RegisterOptions(match='exact'),
)
print("registered 'should.work' with id {}".format(res.id))

try:
res = yield from session.register(
res = await session.register(
lambda: None, "prefix.fail.",
options=RegisterOptions(match='prefix'),
)
Expand All @@ -32,7 +30,7 @@ def main(reactor, session):
print("prefix-match 'prefix.fail.' failed as expected: {}".format(e.error))

print("calling 'example.foo'")
res = yield from session.call("example.foo")
res = await session.call("example.foo")
print("example.foo() = {}".format(res))

print("done")
Expand Down
1 change: 0 additions & 1 deletion examples/asyncio/wamp/overview/frontend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from os import environ
import asyncio
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner


Expand Down
4 changes: 2 additions & 2 deletions examples/asyncio/wamp/pubsub/options/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def on_event(i):
counter = 0
while True:
publication = await self.publish('com.myapp.topic1',
counter,
options=PublishOptions(acknowledge=True, exclude_me=False))
counter,
options=PublishOptions(acknowledge=True, exclude_me=False))
print("Event published with publication ID {}".format(publication.id))
counter += 1
await asyncio.sleep(1)
Expand Down
3 changes: 1 addition & 2 deletions examples/asyncio/wamp/pubsub/options/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ def on_event(i, details=None):
if self.received > 5:
self.leave()

await self.subscribe(on_event, 'com.myapp.topic1',
options=SubscribeOptions(details_arg='details'))
await self.subscribe(on_event, 'com.myapp.topic1', options=SubscribeOptions(details_arg='details'))

def onDisconnect(self):
asyncio.get_event_loop().stop()
Expand Down

0 comments on commit 68dc8c6

Please sign in to comment.