BTW, the multiprocessing module IMHO has suspect code at one point. I have posted a question on Python mailing list about it to see what response I get. Discussion at:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/849f3bad92011db7# In short, rather than call sys.stdin.close() it calls os.close(sys.stdin.fileno()). This will fail though where sys.stdin has been replaced with a file like object which doesn't have a fileno() method. I don't really understand why they would use os.close() rather than the objects own close() method. Graham 2009/2/18 Graham Dumpleton <[email protected]>: > 2009/2/18 Tom Davis <[email protected]>: >> >> I am trying to use multiprocessing within a modwsgi app and am having >> an issue. At first I was getting errors regarding permissions to use >> stdout, etc. I fixed these by setting WSGIRestrictStdout, >> WSGIRestrictStdin, and WSGIRestrictSignal to Off in my conf file. Now >> I get no errors, but the process doesn't actually run. My usage is >> quite simple: on a page request, I try something along the lines of: >> >> p = multiprocessing.Process(target=fn, args...) >> p.start() >> p.join() >> >> The target doesn't output anything, but if run properly it should add >> some records to the database. I tested that it works normally by >> running the app under the django development server, which doesn't >> seem to have an issue with multiprocessing. Has anyone encountered >> this before? > > What does the target function do? > > Try following WSGI script file. Note that for this script you will > need to look in main Apache error log for output, even if WSGI script > defined in VirtualHost context and that VirtualHost has its own error > log. This is because am reseting stdin/stdout/stderr back to original > values. Take out the WSGIRestrictStdin, WSGIRestrictStdout and > WSGIRestrictSignal directives you already added. > > from multiprocessing import Process > > import sys, os > > sys.stdin = sys.__stdin__ > sys.stdout = sys.__stdout__ > sys.stderr = sys.__stderr__ > > def f(name): > sys.stderr.write('subprocess pid %d\n' % os.getpid()) > sys.stderr.write('hello %s\n' % name) > sys.stderr.flush() > > def application(environ, start_response): > status = '200 OK' > output = 'Hello World!' > > sys.stderr.write('parent pid %d\n' % os.getpid()) > sys.stderr.flush() > > p = Process(target=f, args=('grumpy',)) > p.start() > p.join() > > response_headers = [('Content-type', 'text/plain'), > ('Content-Length', str(len(output)))] > start_response(status, response_headers) > > return [output] > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en -~----------~----~----~----~------~----~------~--~---
