[Python] mod_wsgi: Error "No such directory" for shutil.rmtree() after mkdtemp()

Discussão em 'Python' iniciado por Stack, Agosto 18, 2025.

  1. Stack

    Stack Membro Participativo

    I'm really confusing about multiple thread in mod_wsgi, even after reading this document

    The main problem is that, how does mod_wsgi call my python scripts?

    To make my question clear, i will conclude it to questions below

    Suppose I have server configured like this:

    WSGIDaemonProcess XXX.com processes=12 threads=20 display-name=%{GROUP}
    WSGIProcessGroup XXX.com
    WSGIScriptAlias /sign /XXX/Http/upload.wsgi


    And I'm using prefork MPM

    And my /XXX/Http/upload.wsgi looks like this:

    class app(object):

    def __init__(self):
    pass

    def __call__(self, environ, start_response):
    temp_unsign = tempfile.mkdtemp()
    temp_signed = tempfile.mkdtemp()

    try:
    response_headers = [('Content-type', 'text/plain;charset=UTF-8'),('Content-Length', str(len('123')))]
    status = '200 OK'
    start_response(status, response_headers)

    return ['123']
    finally:
    shutil.rmtree(temp_unsign)
    shutil.rmtree(temp_signed)

    application = app()


    Them my questions are:

    1. If there're 5 requests from different IP at the same time, how many app instances will be there? One instance ? Or one instance per request
    2. What if there're 5 requests from same IP and same computer at the same time?
    3. Does all 5 __call__ methods run in 5 different threads?

    I ask this because I always get error No such directory when execute shutil.rmtree.

    And of course, i can't understand how does mod_wsgi actually work in the matter of multiple thread

    Continue reading...

Compartilhe esta Página