mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -05:00
Handle deprecations in asyncio (#3509)
* passing loop to certain things was deprecated. additionally, `asyncio.get_event_loop()` is being deprecated * awesome, checks are functioning as intended * fun with fixtures * we can just stop misuing that anyhow * Update redbot/pytest/downloader.py Co-Authored-By: jack1142 <6032823+jack1142@users.noreply.github.com> Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Discord Version check
|
||||
|
||||
import asyncio
|
||||
import functools
|
||||
import getpass
|
||||
@@ -20,7 +18,7 @@ from typing import NoReturn
|
||||
|
||||
import discord
|
||||
|
||||
# Set the event loop policies here so any subsequent `get_event_loop()`
|
||||
# Set the event loop policies here so any subsequent `new_event_loop()`
|
||||
# calls, in particular those as a result of the following imports,
|
||||
# return the correct loop object.
|
||||
from redbot import _update_event_loop_policy, __version__
|
||||
@@ -298,7 +296,8 @@ def handle_edit(cli_flags: Namespace):
|
||||
"""
|
||||
This one exists to not log all the things like it's a full run of the bot.
|
||||
"""
|
||||
loop = asyncio.get_event_loop()
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
data_manager.load_basic_configuration(cli_flags.instance_name)
|
||||
red = Red(cli_flags=cli_flags, description="Red V3", dm_help=None, fetch_offline_members=True)
|
||||
try:
|
||||
@@ -310,6 +309,7 @@ def handle_edit(cli_flags: Namespace):
|
||||
print("Aborted!")
|
||||
finally:
|
||||
loop.run_until_complete(asyncio.sleep(1))
|
||||
asyncio.set_event_loop(None)
|
||||
loop.stop()
|
||||
loop.close()
|
||||
sys.exit(0)
|
||||
@@ -460,7 +460,8 @@ def main():
|
||||
handle_edit(cli_flags)
|
||||
return
|
||||
try:
|
||||
loop = asyncio.get_event_loop()
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
if cli_flags.no_instance:
|
||||
print(
|
||||
@@ -524,6 +525,7 @@ def main():
|
||||
# results in a resource warning instead
|
||||
log.info("Please wait, cleaning up a bit more")
|
||||
loop.run_until_complete(asyncio.sleep(2))
|
||||
asyncio.set_event_loop(None)
|
||||
loop.stop()
|
||||
loop.close()
|
||||
exit_code = red._shutdown_mode if red is not None else 1
|
||||
|
||||
Reference in New Issue
Block a user