Skip to content

Commit

Permalink
Merge 15a25be into db48418
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed May 4, 2021
2 parents db48418 + 15a25be commit df6142e
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions soco/events_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ async def before_shutdown():
await sub2.unsubscribe()
await events_asyncio.event_listener.async_stop()
await asyncio.sleep(1)
print("Renewing subscription..")
await sub.renew()
await asyncio.sleep(100)
await before_shutdown()
Expand Down Expand Up @@ -268,11 +272,18 @@ async def _async_start(self):

async def async_stop(self):
"""Stop the listener."""
await self.site.stop()
await self.runner.cleanup()
await self.session.close()
self.sock.close()
self.sock = None
if self.site:
await self.site.stop()
self.site = None
if self.runner:
await self.runner.cleanup()
self.runner = None
if self.session:
await self.session.close()
self.session = None
if self.sock:
self.sock.close()
self.sock = None
self.port = None
self.ip_address = None

Expand Down Expand Up @@ -404,7 +415,7 @@ async def renew(
"""
try:
return await self._wrap(super().renew, requested_timeout, is_autorenew)
return await super().renew(requested_timeout, is_autorenew)
except Exception as exc: # pylint: disable=broad-except
msg = (
"An Exception occurred. Subscription to"
Expand Down Expand Up @@ -443,7 +454,10 @@ async def unsubscribe(
`Subscription`: The Subscription instance.
"""
try:
return await self._wrap(super().unsubscribe)
unsub = super().unsubscribe()
if unsub is None:
return
await unsub
except Exception as exc: # pylint: disable=broad-except
if strict:
raise
Expand Down Expand Up @@ -490,20 +504,6 @@ async def _async_make_request():

return _async_make_request()

async def _wrap(self, method, *args):

"""Wrap a call into an awaitable."""
future = asyncio.Future()

def _wrap_action():
try:
future.set_result(method(*args))
except Exception as ex: # pylint: disable=broad-except
future.set_exception(ex)

asyncio.get_event_loop().call_soon(_wrap_action)
return await future


class nullcontext: # pylint: disable=invalid-name
"""Context manager that does no additional processing.
Expand Down

0 comments on commit df6142e

Please sign in to comment.