I have two python programs running infinitely.
The first process uses Twisted and Autobahn to receive data from a WebSocket feed. It is an infinite loop.
The second process uses a custom library to receive data from Pusher WebSocket feed. It is also an infinite loop.
I am seeking for a way to make these two processes communicate with a third process. This third process must be able to communicate bidirectionally with both processes. Hence, the third process must be able to push and receive messages from the two programs.
I tried to use multiprocessing and Queue but without success.
This is the first process:
from twisted.internet import reactor
from autobahn.twisted.websocket import WebSocketClientFactory, WebSocketClientProtocol, connectWS
import json
class ClientProtocol(WebSocketClientProtocol):
...
def onMessage(self, msg, binary):
...
# Send data to third process
...
if __name__ == '__main__':
factory = WebSocketClientFactory("wss://feed.com")
factory.protocol = ClientProtocol
connectWS(factory)
reactor.run()
This is the second process:
import pusherclient
import sys, time
import json
def callback(event):
...
# Send data to third process
global pusher
def connect_handler(data):
channel = pusher.subscribe('order_book')
channel.bind('data', callback)
...
pusher.connect()
while True:
time.sleep(1)