taslim19
commited on
Commit
·
41a9d86
1
Parent(s):
dc005eb
Fix asyncio event loop conflict between bot and web server
Browse files- OneApi/__main__.py +16 -8
OneApi/__main__.py
CHANGED
@@ -38,12 +38,20 @@ app = cors(app, allow_origin="*")
|
|
38 |
async def home():
|
39 |
return jsonify({'success': 'server online'}), 200
|
40 |
|
41 |
-
async def main():
|
42 |
-
# Start the bot
|
43 |
-
await start_bot()
|
44 |
-
|
45 |
-
# Start the web server
|
46 |
-
await app.run_task(host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
|
47 |
-
|
48 |
if __name__ == '__main__':
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
async def home():
|
39 |
return jsonify({'success': 'server online'}), 200
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
if __name__ == '__main__':
|
42 |
+
# Start the bot in a separate thread
|
43 |
+
import threading
|
44 |
+
import asyncio
|
45 |
+
|
46 |
+
def run_bot():
|
47 |
+
loop = asyncio.new_event_loop()
|
48 |
+
asyncio.set_event_loop(loop)
|
49 |
+
loop.run_until_complete(start_bot())
|
50 |
+
loop.run_forever()
|
51 |
+
|
52 |
+
# Start bot in background thread
|
53 |
+
bot_thread = threading.Thread(target=run_bot, daemon=True)
|
54 |
+
bot_thread.start()
|
55 |
+
|
56 |
+
# Start the web server in main thread
|
57 |
+
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
|