Update bot.py
Browse files
bot.py
CHANGED
|
@@ -199,11 +199,22 @@ if __name__ == "__main__":
|
|
| 199 |
# Apply nest_asyncio to support nested event loops if required.
|
| 200 |
nest_asyncio.apply()
|
| 201 |
try:
|
| 202 |
-
asyncio.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
except Exception as e:
|
| 204 |
logger.error(f"Error in main loop: {e}")
|
| 205 |
print(f"Error in main loop: {e}")
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
# Instead of asyncio.run(), which may try to close an already running loop,
|
| 209 |
# get the current loop and run main() until complete.
|
|
|
|
| 199 |
# Apply nest_asyncio to support nested event loops if required.
|
| 200 |
nest_asyncio.apply()
|
| 201 |
try:
|
| 202 |
+
loop = asyncio.get_event_loop()
|
| 203 |
+
if loop.is_running():
|
| 204 |
+
# If an event loop is already running, schedule main() as a task
|
| 205 |
+
loop.create_task(main())
|
| 206 |
+
else:
|
| 207 |
+
loop.run_until_complete(main())
|
| 208 |
except Exception as e:
|
| 209 |
logger.error(f"Error in main loop: {e}")
|
| 210 |
print(f"Error in main loop: {e}")
|
| 211 |
|
| 212 |
+
# try:
|
| 213 |
+
# asyncio.run(main())
|
| 214 |
+
# except Exception as e:
|
| 215 |
+
# logger.error(f"Error in main loop: {e}")
|
| 216 |
+
# print(f"Error in main loop: {e}")
|
| 217 |
+
|
| 218 |
|
| 219 |
# Instead of asyncio.run(), which may try to close an already running loop,
|
| 220 |
# get the current loop and run main() until complete.
|