Exemple #1
0
class make_server(object):
    """ Wrapper around server to ensure it's stopped
    """
    def __init__(self, address=default_address, app=app, **kw):
        self.server = WSGIServer(address, app, **kw)
        self.server.start()

    def __enter__(self):
        return self.server

    def __exit__(self, exc_type, exc_value, traceback):
        self.server.stop()

    def __del__(self):
        if hasattr(self, 'server'):
            self.server.stop()
Exemple #2
0
class make_server_conn(object):
    
    def __init__(self, address=default_address, app=app, **server_params):
        self.address = address
        self.app = app
        self.server_params = server_params

    def __enter__(self):
        self.server = WSGIServer(self.address, self.app, **self.server_params)
        self.server.start()
        self.conn = make_connection(self.address)
        return self.conn.__enter__()
    
    def __exit__(self, exc_type, exc_value, traceback):
        try:
            self.conn.__exit__(exc_type, exc_value, traceback)
        finally:
            self.server.stop()