示例#1
0
文件: main.py 项目: prymatex/prymatex
def worker_multiplexer(queue_multiplexer, queue_notifier):
    global shutdown

    def debug(*args, **kwargs):
        print(args, kwargs)

    multiplexer = Multiplexer(queue_notifier)
    while not shutdown:
        pycmd = queue_multiplexer.get()
        getattr(multiplexer, pycmd["command"], debug)(*pycmd["args"])
        if pycmd['command'] == 'buried_all':
            break
    multiplexer.stop()
示例#2
0
文件: __init__.py 项目: vognev/dhns
class DhcpNameserver:
    def __init__(self):
        self.dns = dnssrv.Handler()
        self.dhcp = dhcpsrv.Handler()
        self.mul = Multiplexer(
            DnsUdpServer(("", int(getenv("DNSPORT", 5353))), self.dns),
            DhcpUdpServer(("", int(getenv("DHCPPORT", 6767))), self.dhcp),
        )
        self.dns.add_middleware(GoogleDnsHandler(), dnssrv.PRIO_LOWEST)

    def start(self):
        self.mul.start()

    def stop(self):
        self.mul.stop()

    def push(self, handler):
        if isinstance(handler, dnssrv.middlewares.Middleware):
            self.dns.add_middleware(handler)
        if isinstance(handler, dhcpsrv.middlewares.Middleware):
            self.dhcp.add_middleware(handler)