mirror of
https://github.com/progval/Limnoria.git
synced 2025-04-25 12:31:04 -05:00
drivers: Fix Python 3.10 support.
the 'loop' argument is no longer allowed, so we have to work around it by creating a coroutine.
This commit is contained in:
parent
f164ac7fbe
commit
5845bc320b
@ -162,7 +162,7 @@ def run():
|
|||||||
loop.set_exception_handler(_loop_exception_handler)
|
loop.set_exception_handler(_loop_exception_handler)
|
||||||
driver_names = []
|
driver_names = []
|
||||||
futures = []
|
futures = []
|
||||||
coroutines = [] # Used to cleanup on shutdown to avoid warnings
|
|
||||||
for (name, driver) in _drivers.items():
|
for (name, driver) in _drivers.items():
|
||||||
if name not in _deadDrivers:
|
if name not in _deadDrivers:
|
||||||
try:
|
try:
|
||||||
@ -172,23 +172,22 @@ def run():
|
|||||||
log.exception('Exception in drivers.run for driver %s:', name)
|
log.exception('Exception in drivers.run for driver %s:', name)
|
||||||
continue
|
continue
|
||||||
driver_names.append(name)
|
driver_names.append(name)
|
||||||
coroutines.append(coroutine)
|
|
||||||
futures.append(future)
|
futures.append(future)
|
||||||
|
|
||||||
gather_task = asyncio.gather(*futures, return_exceptions=True, loop=loop)
|
async def run_drivers():
|
||||||
timeout_gather_task = asyncio.wait_for(
|
|
||||||
gather_task,
|
await asyncio.wait_for(
|
||||||
timeout=conf.supybot.drivers.poll())
|
asyncio.gather(*futures, return_exceptions=True),
|
||||||
coroutines.append(timeout_gather_task)
|
timeout=conf.supybot.drivers.poll())
|
||||||
|
task = asyncio.ensure_future(run_drivers(), loop=loop)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(timeout_gather_task)
|
loop.run_until_complete(task)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
# Cleanup all the objects so they don't throw warnings.
|
# Finish running what we already had going, then stop.
|
||||||
gather_task.cancel()
|
# This avoids annoying warnings like this:
|
||||||
for future in futures:
|
# RuntimeWarning: coroutine 'SocketDriver._read' was never awaited
|
||||||
future.cancel()
|
loop.run_until_complete(task)
|
||||||
for coroutine in coroutines:
|
|
||||||
coroutine.close()
|
|
||||||
raise
|
raise
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user