Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've tested the code below on Windows XP and on OSX 10.6.6 (shell) and it exits without waiting for the child process to finish.</p> <p><strong>invoke.py:</strong></p> <pre><code>from subprocess import Popen, PIPE import platform if platform.system() == 'Windows': close_fds=False else: close_fds=True p = Popen('python long.py', stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=close_fds, shell=True) print "Content-Type: text/plain\n" print "invoked (%d)" % (p.pid) </code></pre> <p><strong>long.py</strong></p> <pre><code>import time import os print "start (%d)" %(os.getpid()) time.sleep(10) print "end (%d)" %(os.getpid()) </code></pre> <p><strong>Update:</strong> Tested on Windows 7 + Apache 2.2.17 + Python 2.7 + mod_wsgi 3.3.</p> <p>mod_wsgi.so file can be downloaded from <a href="http://code.google.com/p/modwsgi/wiki/DownloadTheSoftware?tm=2" rel="nofollow">here</a>. File should be renamed to mod_wsgi.so and and placed in apache modules folder.</p> <p><strong>invoke.wsgi:</strong> from subprocess import Popen, PIPE import platform</p> <pre><code>def application(environ, start_response): if platform.system() == 'Windows': close_fds=False else: close_fds=True p = Popen('python "C:\testing\long.py"', stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=close_fds, shell=True) status = '200 OK' output = "invoked (%d)" % (p.pid) response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] </code></pre> <p><strong>long.py</strong> file was left unchanged.</p> <p>changes made to <strong>httpd.conf</strong>:</p> <p>append wsgi module: </p> <pre><code>LoadModule wsgi_module modules/mod_wsgi.so </code></pre> <p>add directory to the config</p> <pre><code>&lt;Directory "C:/testing"&gt; AllowOverride None Options None Order allow,deny Allow from all &lt;/Directory&gt; </code></pre> <p>link url with directory</p> <pre><code>Alias /testapp "C:\testing" </code></pre> <p>link url with wsgi app</p> <pre><code>WSGIScriptAlias /testapp "C:\testing\invoke.wsgi" </code></pre> <p>Restart web server. Go <a href="http://server_name/testapp" rel="nofollow">http://server_name/testapp</a> App should show process id and exit.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload