[modwsgi] mod_wsgi + multiprocessing

2011-05-02 Thread Ed Summers
Hi all,

I asked this over on web-sig [1] earlier today, but am asking here
since it looks to only mod_wsgi related...

I've been trying to use the multiprocessing [2] w/ mod_wsgi and have
noticed what appears to be deadlocking behavior with body django and
web.py.  I created a minimal example with web.py to demonstrate [3].

If you have mod_wsgi and web.py available, and and put something like
this in your apache config:

WSGIScriptAlias /multiprocessing /home/ed/wsgi_multiprocessing.py
AddType text/html .py

then visit:

http://localhost/

and compare with:

http://localhost/?multiprocessing=1

you should see the second URL hang.

Going forward I'm most likely going to move this functionality to an
asynchronous queue (celery, etc) but I was wondering if
multiprocessing + mod_wsgi was generally known to be something to
avoid, or if it was even forbidden somehow.

Any assistance you can provide would be welcome.

//Ed


[1] http://mail.python.org/pipermail/web-sig/2011-May/005065.html
[2] http://docs.python.org/library/multiprocessing.html
[3] https://gist.github.com/951570

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



[modwsgi] Re: mod_wsgi + multiprocessing

2011-05-02 Thread Ed Summers
'
     output = 'Hello World!'

     response_headers = [('Content-type', 'text/plain'),
                         ('Content-Length', str(len(output)))]
     start_response(status, response_headers)

     def x(y):
       print os.getpid(), 'x', y
       return y

     print 'map call'
     result = pool.map(x, [1])
     print os.getpid(), 'doit', result

     return [output]

 Then one does get pickle errors, albeit for a different reason:

 [Tue May 03 09:52:59 2011] [info] [client 127.0.0.1] mod_wsgi
 (pid=33010, process='hello-1',
 application='hello-1.example.com|/mptest.wsgi'): Loading WSGI script
 '/Library/WebServer/Sites/hello-1/htdocs/mptest.wsgi'.
 [Tue May 03 09:52:59 2011] [error] create pool
 [Tue May 03 09:52:59 2011] [error] map call
 [Tue May 03 09:52:59 2011] [error] Exception in thread Thread-1:
 [Tue May 03 09:52:59 2011] [error] Traceback (most recent call last):
 [Tue May 03 09:52:59 2011] [error]   File
 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/thr 
 eading.py,
 line 522, in __bootstrap_inner
 [Tue May 03 09:52:59 2011] [error]     self.run()
 [Tue May 03 09:52:59 2011] [error]   File
 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/thr 
 eading.py,
 line 477, in run
 [Tue May 03 09:52:59 2011] [error]     self.__target(*self.__args,
 **self.__kwargs)
 [Tue May 03 09:52:59 2011] [error]   File
 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/mul 
 tiprocessing/pool.py,
 line 225, in _handle_tasks
 [Tue May 03 09:52:59 2011] [error]     put(task)
 [Tue May 03 09:52:59 2011] [error] PicklingError: Can't pickle type
 'function': attribute lookup __builtin__.function failed

 So, it is doing pickling in some form, which isn't going to work for
 stuff in WSGI script file.

 If you really want to pursue this, then suggest you move this code
 outside of the WSGI script file and put it in a standard module on the
 Python module search path you have set up for application.

 Overall though, I would recommend against using multiprocessing module
 from inside of mod_wsgi.

 Graham

 On 2 May 2011 23:37, Ed Summers ed.summ...@gmail.com wrote:







  Hi all,

  I asked this over on web-sig [1] earlier today, but am asking here
  since it looks to only mod_wsgi related...

  I've been trying to use the multiprocessing [2] w/ mod_wsgi and have
  noticed what appears to be deadlocking behavior with body django and
  web.py.  I created a minimal example with web.py to demonstrate [3].

  If you have mod_wsgi and web.py available, and and put something like
  this in your apache config:

     WSGIScriptAlias /multiprocessing /home/ed/wsgi_multiprocessing.py
     AddType text/html .py

  then visit:

     http://localhost/

  and compare with:

     http://localhost/?multiprocessing=1

  you should see the second URL hang.

  Going forward I'm most likely going to move this functionality to an
  asynchronous queue (celery, etc) but I was wondering if
  multiprocessing + mod_wsgi was generally known to be something to
  avoid, or if it was even forbidden somehow.

  Any assistance you can provide would be welcome.

  //Ed

  [1]http://mail.python.org/pipermail/web-sig/2011-May/005065.html
  [2]http://docs.python.org/library/multiprocessing.html
  [3]https://gist.github.com/951570

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

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