Source

kahgean / test / simple_daemon.py

"""A simple XML-RPC Server for test_daemonize.py"""

import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

from SimpleXMLRPCServer import SimpleXMLRPCServer
from kahgean.options import Options
from kahgean import logkit
from kahgean import daemonize

def getpid():
    return os.getpid()

def ping():
    return 'pong'


if __name__ == '__main__':
    options = Options()
    options.add_option('--port', type=int, default=38080)
    logkit.append_options(options)
    daemonize.append_options(options)
    options.parse_options()
    logkit.deal_with_options(options)
    daemonize.deal_with_options(options)
    server = SimpleXMLRPCServer(("localhost", options.get('port')))
    server.register_function(getpid, 'getpid')
    server.register_function(ping, 'ping')
    server.serve_forever()