Launching a httpdserver

RoboFont Forums Help / General Launching a httpdserver

This topic contains 1 reply, has 2 voices, and was last updated by  frederik 3 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6289

    bahman
    Participant

    I’m using a browser inside RF for testing fonts inside the app without any need to launch another program. So far the idea is working very well. But for some reason I need to launch a http server inside the RF which seems to be impossible. Running a simple http server outside RF is very simple. I just need to run this in shell:

    > cd cwd
    > python -m SimpleHTTPServer 8080

    I’ve realized that every python command should be terminated in the Robofont and if the command is still running the app halts and launching the HTTPServer makes the app hang. If it was possible to run the server on another thread it would be great too but when the server is launched on another thread with the following method the server terminates after the interpreter reaches the last line.

    
    import threading
    import SimpleHTTPServer
    import SocketServer
    class RunHttpdServer():
        """
        Runs a httpd server on another thread so you can
        do other things while the server is running.
        """
        def __init__(self):
            self.Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
            self.port = 8000
            self.address = ''
            while True:
                try:
                    self.httpd = SocketServer.TCPServer(('', self.port), self.Handler)
                    self.address = 'http://localhost:%s/' %self.port
                    print 'Serving on address:\n%s' %self.address
                    self.thread = threading.Thread(target = self.httpd.serve_forever)
                    self.thread.daemon = True
                    self.thread.start()
                except SocketServer.socket.error as exc:
                    if exc.args[0] != 48:
                        raise
                    print 'Port', self.port, 'already in use'
                    self.port += 1
                else:
                    break
        def stop(self):
            self.httpd.shutdown()
            print 'Server terminated on the address:\n%s' %self.address
    r = RunHttpdServer()
    

    I can use the time.sleep(10) to make the server alive but it will also make the app hang. Do you think is there anyway to launch the server within RF and making it run forever (or a limited time) without making the RF hang? For example like launching another process in the background.

    Thanks in advance

    #6292

    frederik
    Keymaster

    As far is I understand this example, this will run forever until a traceback is raised.

    This seems to work fine with an htmlView inside RoboFont.

    Good luck

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.