Threads with mod_wsgi

44 views
Skip to first unread message

Phyllipe

unread,
Feb 11, 2012, 2:08:36 PM2/11/12
to modwsgi
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!)

Graham Dumpleton

unread,
Feb 11, 2012, 4:19:14 PM2/11/12
to mod...@googlegroups.com
What are you making the HTTP request to? How do you know it is going
into an infinite loop and what specifically is going into an infinite
loop?

Some more detail would be helpful in understanding the issue.

Graham

> --
> You received this message because you are subscribed to the Google Groups "modwsgi" group.
> To post to this group, send email to mod...@googlegroups.com.
> To unsubscribe from this group, send email to modwsgi+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
>

Phyllipe Medeiros

unread,
Feb 12, 2012, 1:04:40 AM2/12/12
to mod...@googlegroups.com
I have something like that:
while True:
 ...try:
........print "HERE"
........response, content = self.http.request('http://www.spoj.pl/', 'POST', headers=self.headers, body=urlencode(self.bodyLogin))
........print "AFTER"
........break;
....except Exception as detail:
.......print "ERROR"
If I execute this without creating a thread, I got: "HERE" and "AFTER"
If I execute this using a thread, I got only: "HERE"
These are my headers and bodyLogin:
self.headers = {
'Content-type': 'application/x-www-form-urlencoded', 
'Accept': 'text/plain'
}
self.bodyLogin = {
'login_user':self.judge_login,
'password':self.judge_passwd,
'autologin':'1',

Graham Dumpleton

unread,
Feb 12, 2012, 3:36:58 AM2/12/12
to mod...@googlegroups.com
So if an exception occurs that isn't derived from Exception class then
it will go into an infinite loop.

Add an 'except:' branch to try after that for Exception.

Graham

Phyllipe Medeiros

unread,
Feb 12, 2012, 12:32:48 PM2/12/12
to mod...@googlegroups.com
But it would print "HERE" so many times, wouldn't it?

Phyllipe Medeiros

unread,
Feb 12, 2012, 12:52:19 PM2/12/12
to mod...@googlegroups.com
Thanks Graham, you gave an idea to test! I thought Exception was the mother class of all other exceptions ;/
I got this
[Sun Feb 12 14:51:42 2012] [error] Traceback (most recent call last):
[Sun Feb 12 14:51:42 2012] [error]   File "/usr/local/lib/python2.7/threading.py", line 530, in __bootstrap_inner
[Sun Feb 12 14:51:42 2012] [error]     self.run()
[Sun Feb 12 14:51:42 2012] [error]   File "/srv/www/ufcgjudge/contests/views.py", line 151, in run
[Sun Feb 12 14:51:42 2012] [error]     response, content = Http("http://www.spoj.pl")
[Sun Feb 12 14:51:42 2012] [error]   File "/usr/local/lib/python2.7/site-packages/httplib2-0.7.2-py2.7.egg/httplib2/__init__.py", line 1073, in __init__
[Sun Feb 12 14:51:42 2012] [error]     self.cache = FileCache(cache)
[Sun Feb 12 14:51:42 2012] [error]   File "/usr/local/lib/python2.7/site-packages/httplib2-0.7.2-py2.7.egg/httplib2/__init__.py", line 687, in __init__
[Sun Feb 12 14:51:42 2012] [error]     os.makedirs(self.cache)
[Sun Feb 12 14:51:42 2012] [error]   File "/usr/local/lib/python2.7/os.py", line 150, in makedirs
[Sun Feb 12 14:51:42 2012] [error]     makedirs(head, mode)
[Sun Feb 12 14:51:42 2012] [error]   File "/usr/local/lib/python2.7/os.py", line 157, in makedirs
[Sun Feb 12 14:51:42 2012] [error]     mkdir(name, mode)
[Sun Feb 12 14:51:42 2012] [error] OSError: [Errno 13] Permission denied: 'http:'
The thing that make me curious is that now when I'm testing only using python, "Http('www.spoj.pl')" I get this too ;/(Even without thread, with sudo goes ok!)
Maybe I need to change some permissions right?
Reply all
Reply to author
Forward
0 new messages