jeudi 31 mars 2016

Python SimpleHTTPServer keeps going down and I don't know why

This is my first time working with SimpleHTTPServer, and honestly my first time working with web servers in general, and I'm having a frustrating problem. I'll start up my server (via SSH) and then I'll go try to access it and everything will be fine. But I'll come back a few hours later and the server won't be running anymore. And by that point the SSH session has disconnected, so I can't see if there were any error messages. (Yes, I know I should use something like screen to save the shell messages -- trying that right now, but I need to wait for it to go down again.)

I thought it might just be that my code was throwing an exception, since I had no error handling, but I added what should be a pretty catch-all try/catch block, and I'm still experiencing the issue. (I feel like this is probably not the best method of error handling, but I'm new at this... so let me know if there's a better way to do this)

class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    # (this is the only function my request handler has)
    def do_GET(self):
        if 'search=' in self.path:
            try:
                # (my code that does stuff)
            except Exception as e:
                # (log the error to a file)
            return
        else:
            SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

Does anyone have any advice for things to check, or ways to diagnose the issue? Most likely, I guess, is that my code is just crashing somewhere else... but if there's anything in particular I should know about the way SimpleHTTPServer operates, let me know.




Aucun commentaire:

Enregistrer un commentaire