def run(configClass): """ Create and run a moin server See StandaloneConfig for available options @param configClass: config class """ # Run only once! global httpd, config if httpd is not None: raise RuntimeError("You can run only one server per process!") config = configClass() # Install hotshot profiled serve_moin method. To compare with other # servers, we profile the part that create and run the request. if config.hotshotProfile: import hotshot config.hotshotProfile = hotshot.Profile(config.hotshotProfile) MoinRequestHandler.serve_moin = hotshotProfileDecorator( MoinRequestHandler.serve_moin, config.hotshotProfile) # Install a memory profiled serve_moin method if config.memoryProfile: config.memoryProfile.sample() MoinRequestHandler.serve_moin = memoryProfileDecorator( MoinRequestHandler.serve_moin, config.memoryProfile) if config.logPath: sys.stderr = file(config.logPath, 'at', 0) registerSignalHandlers(quit) httpd = makeServer(config) # Run as a safe user (posix only) if os.name == 'posix' and os.getuid() == 0: switchUID(config.uid, config.gid) httpd.serve_forever()
def run(configClass): """ Create and run a moin server See StandaloneConfig for available options @param configClass: config class """ # set globals (only on first import, save from reloads!) global httpd global config # Create config instance (raise RuntimeError if config invalid) config = configClass() # register signal handler signal.signal(signal.SIGABRT, quit) signal.signal(signal.SIGINT, quit) signal.signal(signal.SIGTERM, quit) # Create error log if config.logPath: sys.stderr = file(config.logPath, 'at') # Start profiler if config.memoryProfile: config.memoryProfile.sample() # create web server httpd = MoinServer((config.interface, config.port), config.docs) # start server # drop root if os.name == 'posix' and os.getuid() == 0: switchUID(config.uid, config.gid) httpd.serve_forever()
def run(configClass): """ Create and run a moin server See StandaloneConfig for available options @param configClass: config class """ # set globals (only on first import, save from reloads!) global httpd global config config = configClass() if config.logPath: sys.stderr = file(config.logPath, 'at') if config.memoryProfile: config.memoryProfile.sample() registerSignalHandlers(quit) httpd = makeServer(config) # If running as root, switch user and group id if os.getuid() == 0 and os.name == 'posix': switchUID(config.uid, config.gid) httpd.serve_forever()
def run(configClass): """ Create and run a moin server See StandaloneConfig for available options @param configClass: config class """ # Run only once! global httpd, config if httpd is not None: raise RuntimeError("You can run only one server per process!") config = configClass() if config.hotshotProfile and config.cProfileProfile: raise RuntimeError("You cannot run two profilers simultaneously.") # Install hotshot profiled serve_moin method. To compare with other # servers, we profile the part that create and run the request. if config.hotshotProfile: import hotshot config.hotshotProfile = hotshot.Profile(config.hotshotProfile) MoinRequestHandler.serve_moin = hotshotProfileDecorator( MoinRequestHandler.serve_moin, config.hotshotProfile) if config.cProfileProfile: import cProfile # Create a new cProfile.Profile object using config.cProfileProfile # as the path for the output file. config.cProfile = cProfile.Profile() MoinRequestHandler.serve_moin = cProfileDecorator( MoinRequestHandler.serve_moin, config.cProfile) # Install a memory profiled serve_moin method if config.memoryProfile: config.memoryProfile.sample() MoinRequestHandler.serve_moin = memoryProfileDecorator( MoinRequestHandler.serve_moin, config.memoryProfile) # initialize pycallgraph, if wanted if config.pycallgraph_output: try: import pycallgraph pycallgraph.settings['include_stdlib'] = False pcg_filter = pycallgraph.GlobbingFilter(exclude=['pycallgraph.*', 'unknown.*', ], max_depth=9999) pycallgraph.start_trace(reset=True, filter_func=pcg_filter) except ImportError: config.pycallgraph_output = None registerSignalHandlers(quit) httpd = makeServer(config) # Run as a safe user (posix only) if os.name == 'posix' and os.getuid() == 0: switchUID(config.uid, config.gid) httpd.serve_forever()