Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64005 > unrolled thread
| Started by | Manish <gill.manish90@gmail.com> |
|---|---|
| First post | 2014-01-15 09:12 -0800 |
| Last post | 2014-01-16 04:40 +1100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Communicate between Python and Node.js Manish <gill.manish90@gmail.com> - 2014-01-15 09:12 -0800
Re: Communicate between Python and Node.js Chris Angelico <rosuav@gmail.com> - 2014-01-16 04:40 +1100
| From | Manish <gill.manish90@gmail.com> |
|---|---|
| Date | 2014-01-15 09:12 -0800 |
| Subject | Communicate between Python and Node.js |
| Message-ID | <1ea934d2-d48b-4857-aa4a-f4d24a9d8552@googlegroups.com> |
I've been tasked to write a module that sends data from Django to a Node.js server running on the same machine. Some magic happens in node and I recv the results back, which are then rendered using Django templates.
At first I thought to use the requests library to GET/POST data to node, but I googled around and it seems lots of people think TCP sockets are the way to go. I tried implementing my own using several examples I have found online. It *kind of* works. It seems like I get blocked while trying to receive data back in the recv() loop. I never reach the end. I'm not an expert in sockets/networking, but maybe I'm not wrong in guessing it is because of the non-blocking nature of Node.js ?
A Stackoverflow post helped a little more in figuring things out (though I'm not sure if I'm correct here). Right now, I'm failing during connect() - I get "Operation now in progress".
So my question is, how can I get recv() to work properly so that data is seamlessly passed back and forth between my Python script and the node server. Am I taking the right approach? Is there any better way?
Relevant scripts:
1) http://bpaste.net/show/NI2z9RhbT3HVtLVWUKuq/
2) http://bpaste.net/show/YlulEZBTDE5KS5ZvSyET/
Thanks!
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-01-16 04:40 +1100 |
| Message-ID | <mailman.5536.1389807613.18130.python-list@python.org> |
| In reply to | #64005 |
On Thu, Jan 16, 2014 at 4:12 AM, Manish <gill.manish90@gmail.com> wrote: > At first I thought to use the requests library to GET/POST data to node, but I googled around and it seems lots of people think TCP sockets are the way to go. I tried implementing my own using several examples I have found online. It *kind of* works. It seems like I get blocked while trying to receive data back in the recv() loop. I never reach the end. I'm not an expert in sockets/networking, but maybe I'm not wrong in guessing it is because of the non-blocking nature of Node.js ? Do you need to use non-blocking sockets here? I think, from a quick skim of your code, that you'd do better with a blocking socket. Tip: Any time you have a sleep(1) call in your code, look to see if it's doing the wrong thing. In this case, I'm pretty sure it is. Sleeping for a second and then trying to read from a nonblocking socket seems like a messy way to just read until you have what you want. There's another thread happening at the moment about networking in Python. You may find it of interest. ChrisA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web