


The first reason being, HTTP sessions have a timeout. It seems your subscribers list depends on currently opened connections.
#SEND DATA ICOLLECTIONS WEBSOKECTS CODE#
I'm not familiar with how websocket works, but from your code I think I can infer it. The last line is commented-out because it doesn't seem necessary, can I remove it? Where would it be necessary?.could a misbehaving subscriber somehow still interfere with the primary purpose? Any edge-cases or unexpected consequences to beware of here? Eg.I've added some precautions by limiting the number of subscribers to prevent overloading the secondary task from gobbling up resources, and I've tried to make sure any disconnects are handled so that it doesn't interfere with the primary purpose. Start_server = rve(subscribe_ws, "localhost", 8765)Īsyncio.get_event_loop().run_until_complete(asyncio.gather(start_server, mirror_ticks())) Ws.send("All client slots are currently in use") # Secondary purpose: Mirror data to Python web-server # Critical primary purpose: Save data to local fileĪsync with aiofiles.open('filename', mode='a') as file: Here is what I have so far: import asyncioįrom websockets.exceptions import ConnectionClosedOKĪsync with nnect("wss://") as ws: Since I may only obtain one copy of a data stream (not this particular Coinbase one it's just a free example), I'd like to add a secondary purpose using websockets to mirror the data for a Python web-server, but absolutely without interfering with the primary purpose above. The original purpose of this script was saving data to a local file, which is still the primary purpose.
