Reputation: 41745
I tried requests
but it seems slow because of the tcp connection takes long (I don't know how to keep the socket open)
I'm now trying zerorpc
and it has notion of persistent connection
.
Django <-> node.js communication works fine for the first message but it fails with Lost remote after 10s heartbeat
error from the second attempt.
I am probably missing something obvious.
# following connection step is done in python a module so that it gets called only one time
import zerorpc
client = zerorpc.Client()
client.connect("tcp://127.0.0.1:7015")
def something(...):
# this gets called for a http request, and we are messaging node.js using the zerorpc client.
...
client.call_rpc(message)
Other clients (from command line) can still talk to server and get a response, so I guess it has to do with the above django code.
Upvotes: 0
Views: 639
Reputation: 633
zerorpc uses gevent for cooperative asynchronous IOs while django handles one request at a time. When django is handling some IOs, zerorpc doesn't get its fair share of CPU time, and cannot handle the heartbeat. Turning off the heartbeat is possible in the zerorpc-python (for this very reason) but is not on zerorpc-node!
One solution is to run django on top of the gevent ioloop, it looks like http://gunicorn.org/ can be of some help.
Upvotes: 2