-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.py
25 lines (21 loc) · 835 Bytes
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from app import app
from websocket_manager import WebSocketManager
import asyncio
import threading
from app.routes import handle_new_transaction # Fixed import
def run_websocket():
async def start_websocket():
ws_manager = WebSocketManager()
ws_manager.add_transaction_callback(handle_new_transaction)
while True:
connected = await ws_manager.connect()
if connected:
await ws_manager.listen()
await asyncio.sleep(5) # Wait before reconnecting
asyncio.run(start_websocket())
if __name__ == '__main__':
# Start WebSocket connection in a separate thread
websocket_thread = threading.Thread(target=run_websocket, daemon=True)
websocket_thread.start()
# Run Flask app
app.run(host='0.0.0.0', port=5000, debug=False, threaded=True)