Problem with py2exe-frozen CGIHttpServer-based script

vincent wehren vincent at visualtrans.de
Wed Nov 26 23:43:47 EST 2003


Hi,

as a small capabilities demo I coded the piece below to show how to use
Python for cgi'ing on localhost and it more or less does the trick :-).
However, I when I freeze it with py2exe, starting the resulting exe fires up
the server allright,
but fails execute cgi commands correctly (i.e. the expected output  - let's
say from cgi.test()) - is no longer emitted to the browser...).

Is there some py2exe-magic I need to do that I don't know of? Something in
the code that prevents the frozen version to work?


Any pointers would be much appreciated...

Python 2.3.2 , Py2exe 0.4.2, Win XP

Here's the code...:


import CGIHTTPServer, BaseHTTPServer, SimpleHTTPServer
import threading
import sys

port=8000

#    nicked from the SimpleHTTPServer test rig
def simple( HandlerClass = SimpleHTTPServer.SimpleHTTPRequestHandler
           ,ServerClass = BaseHTTPServer.HTTPServer):
    """
    """

    base(HandlerClass, ServerClass)


#    nicked from the BaseHTTPServer test rig
def base(HandlerClass = BaseHTTPServer.BaseHTTPRequestHandler,
         ServerClass = BaseHTTPServer.HTTPServer, protocol="HTTP/1.0"):
    """
    """

    server_address = ('localhost', port)
    HandlerClass.protocol_version = protocol
    try:
        httpd = ServerClass(server_address, HandlerClass)
        sa = httpd.socket.getsockname()
        print "Serving HTTP on", sa[0], "port", sa[1], "..."
        httpd.serve_forever()
    except KeyboardInterrupt:
        http.socket.close()



def RunServer(readyEvent=None
              ,HandlerClass = CGIHTTPServer.CGIHTTPRequestHandler
              ,ServerClass = BaseHTTPServer.HTTPServer):

    simple(HandlerClass, ServerClass)
    if readyEvent:
        readyEvent.set()

def main():

    testServerReady = threading.Event()
    threading.Thread(target=RunServer, args=(testServerReady,)).start()
    testServerReady.wait()


if __name__ == '__main__':
    main()












More information about the Python-list mailing list