On Feb 17, 9:36 am, justind <justin.don...@gmail.com> wrote: > I have an unusual Django application. I was wondering if someone could > offer advice to the best way to handle a requirement. This isn't a > standard application (and might not even seem like a good use of > Django, but that's beside the point.) > > Redhat, Python 2.4, Django 1.1, mod_wsgi. > > In a view, I need to open a socket, send a message to a piece of > hardware,then close the socket and return the view. However, the > hardware takes n milliseconds to do its thing, and if the socket > closes while its doing its thing (even if its received its entire > message), it stops what its supposed to do, which is bad. > > The hardware is fire and forget. It doesn't return a response. There's > no need to keep the view waiting, except I need to keep that socket > open so it continues.
So there is no way to know how long to keep the socket open? If so than in your view there is nothing better than to time.sleep some arbitrary time. It sounds like you want to have the code that communicates with the server in its own process. Your Django view would then communicate with this process and the process would keep the socket open to the hardware all the time. There are a number of choices to communicate with your process - but you could use named pipes, sockets (local server), or a message_queue like rabbitMQ/Celery -Preston > > As a stopgap meaure, I've just been using time.sleep to hold the view. > This works, but its hideous. > > I tried running all the socket communication in a seperate deamon > thread, but this didn't change anything. When the view returned, the > socket closed, the hardware stopped. > > What is a better solution to this problem? Actually, I feel like I > can't solve it because I lack an understanding at what's happening > where Django touches Apache and I'd like to fill that gap, so in > addition to help with this particular problem, descriptions of what's > going on at apache/mod_wsgi process level and how that interacts with > me spawning threads etc (or pointers to docs) would help me out and be > appreciated. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.