Tuesday, March 30, 2010

Trouble using sockets in Django view

I ran into an issue while writing socket communication in code that was called by a Django view handler. After a Twisted-based and socket-based solution failed mysteriously, I discovered a telnet-based solution that worked.

Read more about it the details here:

http://wiki.devinvenable.com/mediawiki/index.php/Interesting_socket_behavior_exhibited_while_processing_Django_view

Comments or insights as to the cause of the problem behavior would be helpful.

2 comments:

宥軒宥軒 said...

good post..................................................

Blaž said...

Strange, on first look when I come across s.recv(300) web server is blocking for around 3 minutes before thread exits if nothing is received from server. If server sends anything, client reads it and stops blocking.

Here is server output:
[Thu Jun 14 09:52:06 2012] [notice] Child 5588: Waiting 270 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:52:36 2012] [notice] Child 5588: Waiting 240 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:53:06 2012] [notice] Child 5588: Waiting 210 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:53:36 2012] [notice] Child 5588: Waiting 180 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:54:06 2012] [notice] Child 5588: Waiting 150 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:54:36 2012] [notice] Child 5588: Waiting 120 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:55:06 2012] [notice] Child 5588: Waiting 90 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:55:36 2012] [notice] Child 5588: Waiting 60 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:56:06 2012] [notice] Child 5588: Waiting 30 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:56:36 2012] [notice] Child 5588: Waiting 0 more seconds for 2 worker threads to finish.
[Thu Jun 14 09:56:37 2012] [notice] Child 5588: Terminating 2 threads that failed to exit.
[Thu Jun 14 09:56:37 2012] [notice] Child 5588: All worker threads have exited.
[Thu Jun 14 09:56:37 2012] [notice] Child 5588: Child process is exiting