Mod_Wsgi + Apache 2.2 + Threads + httplib2

72 views
Skip to first unread message

Phyllipe

unread,
Feb 11, 2012, 9:37:58 AM2/11/12
to Django users
I have a python file that works as well, it connects in another
website, doing something like that:
'response, content = self.http.request('http://www.spoj.pl/', 'POST',
headers=self.headers, body=urlencode(self.bodyLogin))'
It goes inside a class, when I run it in a thread it does not works.
If I try with runserver it works as well! But with Apache2 and
MOD_WSGI doesnt work!
I debugged somethings, I've tried to connect without using the
thread(calling the method in some view) and it worked.
But when I use my SingleTon class that has a bounded semaphores that
creates a thread and in that thread class this method that was talking
before, it stops in the response, content part.
So I did a little more tests, I've created a thread in my views and in
that thread called this method exactly the same way that I called
without threads and that worked, but it has not worked ;/
I've putted some prints in my code that is how I discovered the line
that has the bug, I've putted a print before call 'response, content'
and a print after, the before print appears but not the last, the
strange thing its that does not raise any kind of exception, cause I
have a try:, except Exception in a while True and it does not executes
the before print again...
some thing like
while True:
....try:
........print
........response....
....except Exception as detail:
.......pass
So I'm pretty sure that my bug is something related to Threads +
httplib2, if I use only httplib2 works as well!
If I use only django server works as well if threads and httplib2.
But when I try to deploy in my university server with apache2 and
mod_wsgi it bugs ;/
At my house with apache2 and mod_wsgi works as well
I have already installed apache2-threaded-dev...

Phyllipe

unread,
Feb 11, 2012, 1:02:28 PM2/11/12
to Django users
My server config: Apache/2.2.14 (Ubuntu) DAV/2 SVN/1.6.6 PHP/
5.3.2-1ubuntu4.10 with Suhosin-Patch mod_wsgi/3.3 Python/2.6.5
configured -- resuming normal operations
There is no error at apache log.
I've tried to put:
try:
...response, content...
...print "NEXT"
except Exception as detail:
..print detail
None of those prints were used ;/ Seems that I get an infinite loop at
response, content...
But just saying again, if I try "response, content" without using a
thread, it works very nice!
And if I try response, content with django webserver it works nice
too!

Phyllipe

unread,
Feb 11, 2012, 2:08:05 PM2/11/12
to Django users
Just to give more details that I think can be relevant:
"Hi everyone,
I have a django application that works pretty fine with django web-
server.
I have a python file that uses Http() from httplib2, it works very
well! But when I create a thread and in this thread use this python
file(more precisely a class) that uses Http() it seems that I got in a
infinite loop.
I am very noob in this kind of problems, but I think the problem is in
Apache or mod_wsgi because if I use django webserver it works as well!
But if I use Apache2 + mod_wsgi it doesn't work! Other strange thing
is that in my house it works ;/, it doesn't work at my server ;(.
If I use this class(that calls Http() ) without a thread involving it,
it works fine too ;/.
This my configuration Apache/2.2.14 (Ubuntu) DAV/2 SVN/1.6.6 PHP/
5.3.2-1ubuntu4.10 with Suhosin-Patch mod_wsgi/3.3 Python/2.7
configured -- resuming normal operations
I have tested with other python version too.
My httpd.conf:
###
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
WSGIScriptAlias / /srv/www/ufcgjudge/apache/django.wsgi
########
At sites-available/ufcgjudge:
"""
WSGIDaemonProcess ufcgjudge processes=2 threads=15 display-name=%
{GROUP}
WSGIProcessGroup ufcgjudge

WSGIScriptAlias / /srv/www/ufcgjudge/apache/django.wsgi
"""
Exactly the same way that is in my house.(And works here!)

sbrandt

unread,
Feb 13, 2012, 9:31:51 AM2/13/12
to Django users
mod_wsgi doesn't support print, does it? Its usage should raise an
exception.

Graham Dumpleton

unread,
Feb 15, 2012, 5:32:59 PM2/15/12
to Django users


On Feb 14, 1:31 am, sbrandt <s.brandt.ber...@googlemail.com> wrote:
> mod_wsgi doesn't support print, does it? Its usage should raise an
> exception.

Yes it does support 'print'. Read:

http://blog.dscpl.com.au/2009/04/wsgi-and-printing-to-standard-output.html

Graham
Reply all
Reply to author
Forward
0 new messages