当前位置: 首页>>代码示例>>Python>>正文


Python pyev.default_loop函数代码示例

本文整理汇总了Python中pyev.default_loop函数的典型用法代码示例。如果您正苦于以下问题:Python default_loop函数的具体用法?Python default_loop怎么用?Python default_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了default_loop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: serve

def serve(address="0.0.0.0",port=24414):
    global config, conn_sock, ifname, tunfd
    name, public_key, secret_key = load_identity()
    if name is not None:
        print("Your identity is:")
        print(name + " " + get_fingerprint(public_key))
        print("Verify this fingerprint is valid when connecting")
    else:
        name, public_key, secret_key = new_key_interface()
    config = configparser.RawConfigParser()
    config.read("netshrink.cfg")
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    conn_sock = sock
    sock.bind((address,port))
    loop = pyev.default_loop()
    io = pyev.Io(sock, pyev.EV_READ, loop, serve_cb)
    io.start()
    sigint = pyev.Signal(2, loop, sigint_cb)
    sigint.start()
    print("Starting tun interface...")
    iface_name = config.get("netshrink", "iface_name").encode("utf8")
    #start the tun interface
    try:
        tunfd = os.open("/dev/net/tun", os.O_RDWR)
        ifname = ioctl(tunfd, TUNSETIFF,
                       struct.pack("16sH", iface_name, IFF_TUN))
    except IOError:
        print("You do not have permissions to create a tunnel interface.")
        sys.exit(1)
    ifname = ifname[:ifname.find(b'\0')]
    tunio = pyev.Io(tunfd, pyev.EV_READ, loop, tun_cb)
    tunio.start()
    print("Listening for new connections")
    loop.start()
开发者ID:k3d3,项目名称:NetShrink,代码行数:34,代码来源:netshrink.py

示例2: __init__

    def __init__(self, start_server_ip="127.0.0.1", start_server_port=5000, num_server_workers=8):

        self.start_server_ip = start_server_ip
        self.start_server_port = start_server_port
        self.num_server_workers = num_server_workers
        self.listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.listen_sock.bind((start_server_ip, start_server_port))
        self.listen_sock.setblocking(0)
        self.listen_sock.settimeout(1)
        self.address = self.listen_sock.getsockname()

        self.worker_procs = []
        self.worker_queues = []

        for i in range(num_server_workers):

            # Create a pair of (inQ,outQ) for IPC with the worker

            worker_in_q = multiprocessing.Queue()
            worker_out_q = multiprocessing.Queue()

            self.worker_queues.append((worker_in_q, worker_out_q))

            # Create the worker process object

            worker_proc = ServerWorker("SW." + str(i + 1), worker_in_q, worker_out_q)

            worker_proc.daemon = True
            self.worker_procs.append(worker_proc)

            # Start the worker process

            worker_proc.start()

        # By now the server workers have been spawned

        # Setup the default Pyev loop in the master

        self.loop = pyev.default_loop(flags=pyev.recommended_backends())

        # Prepare signal , out Q and connection watchers

        self.sig_watchers = [pyev.Signal(sig, self.loop, self.signal_cb) for sig in STOPSIGNALS]

        self.q_watchers = [
            pyev.Io(
                fd=worker.out_q._reader.fileno(),
                events=pyev.EV_READ,
                loop=self.loop,
                callback=self.out_q_cb,
                data=worker,
            )
            for worker in self.worker_procs
        ]

        self.socket_watchers = [
            pyev.Io(fd=self.listen_sock.fileno(), events=pyev.EV_READ, loop=self.loop, callback=self.io_cb)
        ]
        self.next_worker = 0
开发者ID:stqism,项目名称:OSIRIS,代码行数:60,代码来源:osirisd.py

示例3: main

def main():
    path = "adder_service"
    name = "adder"

    loop = pyev.default_loop()

    sigwatcher = pyev.Signal(signal.SIGINT, loop, lambda watcher, events: watcher.loop.stop(pyev.EVBREAK_ALL))
    sigwatcher.start()

    service = spawn(Adder, loop, name, path)
    sproxy = ServiceProxy(loop, path)

    sproxy.connect()

    clients = []
    proxies = []

    # to push the server further (to see how fast it will really go...)
    # just add more clients!
    for x in range(30):
        bpath = "adder_bench_%i" % x
        client = spawn(AdderBench, loop, bpath, bpath, path)
        bproxy = ServiceProxy(loop, "adder_bench_1")
        bproxy.connect()
        clients.append(client)
        proxies.append(bproxy)

    loop.start()
开发者ID:bfrog,项目名称:whizzer,代码行数:28,代码来源:servicefork.py

示例4: __init__

    def __init__(self, address=("",8888), console=("",9876)):

        # init proxy socket
        self.sock = socket.socket()
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.sock.bind(address)
        self.sock.setblocking(0)
        self.proxyaddress = self.sock.getsockname()
 
        # init console socket
        self.console = socket.socket()
        self.console.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.console.bind(console)
        self.console.setblocking(0)
        self.consoleaddress = self.console.getsockname()
 
        self.loop = pyev.default_loop()
        self.watchers = [pyev.Signal(sig, self.loop, self.signal_cb)
                         for sig in STOPSIGNALS]
        self.watchers.append(pyev.Io(self.sock._sock, pyev.EV_READ, self.loop,
                                    self.io_cb))

        self.watchers.append(pyev.Io(self.console._sock, pyev.EV_READ, self.loop,
                                     self.console_cb))

        self.connection_count = 0
        self.conns = {}
开发者ID:yayv,项目名称:proxython,代码行数:27,代码来源:main.py

示例5: __init__

    def __init__(
        self,
        parameters=None,
        on_open_callback=None,
        on_open_error_callback=None,
        on_close_callback=None,
        stop_ioloop_on_close=False,
        custom_ioloop=None,
        on_signal_callback=None,
    ):
        """Create a new instance of the LibevConnection class, connecting
        to RabbitMQ automatically

        :param pika.connection.Parameters parameters: Connection parameters
        :param on_open_callback: The method to call when the connection is open
        :type on_open_callback: method
        :param on_open_error_callback: Method to call if the connection cannot
                                       be opened
        :type on_open_error_callback: method
        :param bool stop_ioloop_on_close: Call ioloop.stop() if disconnected
        :param custom_ioloop: Override using the default IOLoop in libev
        :param on_signal_callback: Method to call if SIGINT or SIGTERM occur
        :type on_signal_callback: method

        """
        self.ioloop = custom_ioloop or pyev.default_loop()
        self._on_signal_callback = on_signal_callback
        self._io_watcher = None
        self._active_timers = {}
        self._stopped_timers = deque()

        super(LibevConnection, self).__init__(
            parameters, on_open_callback, on_open_error_callback, on_close_callback, self.ioloop, stop_ioloop_on_close
        )
开发者ID:tonyg,项目名称:pika,代码行数:34,代码来源:libev_connection.py

示例6: __init__

    def __init__(self, 
            start_client_ip="127.0.0.1",
            start_client_port=10000,
            end_client_port=60000,
            num_cnxn_per_client=10,
            num_cnxn_per_sec=1,
            start_server_ip="127.0.0.1",
            start_server_port=5000,
            num_client_workers=1):

        self.worker_procs = []
        self.worker_queues = []

        client_ip = start_client_ip
        server_ip = start_server_ip

        for i in range(num_client_workers):

            # Create a pair of (inQ,outQ) for IPC with the worker
            worker_in_q = multiprocessing.Queue()
            worker_out_q = multiprocessing.Queue()

            self.worker_queues.append((worker_in_q,worker_out_q))

            # Create the worker process object
            worker_proc = ClientWorker("CW."+str(i+1), 
                                       worker_in_q,
                                       worker_out_q,
                                       client_ip,
                                       start_client_port,
                                       end_client_port,
                                       num_cnxn_per_client,
                                       num_cnxn_per_sec,
                                       server_ip,
                                       start_server_port 
                                       )

            worker_proc.daemon = True
            self.worker_procs.append(worker_proc)
        
            # Start the worker process
            worker_proc.start()
    
        # By now the client workers have been spawned

        # Setup the default Pyev loop in the master 
        self.loop = pyev.default_loop(flags=pyev.EVBACKEND_EPOLL)

        # Prepare signal and out Q watchers
        self.sig_watchers = [pyev.Signal(sig, self.loop, self.signal_cb)
                              for sig in STOPSIGNALS]

        self.q_watchers = [pyev.Io(fd=worker.out_q._reader.fileno(), 
                                  events=pyev.EV_READ,
                                  loop=self.loop, 
                                  callback=self.out_q_cb,
                                  data=worker)
                            for worker in self.worker_procs]
开发者ID:jeeveeyes,项目名称:pyev-test,代码行数:58,代码来源:multi_proc_client.py

示例7: __init__

 def __init__(self, address):
         self.sock = socket.socket()
         self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         self.sock.bind(address)
         self.sock.setblocking(0)
         self.address = self.sock.getsockname()
         self.loop = pyev.default_loop()
         self.watchers = [pyev.Signal(sig, self.loop, self.signal_cb) for sig in STOPSIGNALS]
         self.watchers.append(pyev.Io(self.sock._sock, pyev.EV_READ, self.loop, self.io_cb))
         self.conns = weakref.WeakValueDictionary()
开发者ID:zhangping,项目名称:directord,代码行数:10,代码来源:evserver.py

示例8: serve

    def serve(self, sock, nevents=None):
        loop = pyev.default_loop()

        self.clients = {}
        main = pyev.Io(sock, pyev.EV_READ, loop, self.accept, data=sock)
        main.start()

        sigint = pyev.Signal(signal.SIGINT, loop, self.sigint, data=[main])
        sigint.start()

        loop.loop()
开发者ID:ikebrown,项目名称:scribbles,代码行数:11,代码来源:httpd-pyev.py

示例9: __init__

 def __init__(self,address):
     self.address = address
     self.sock = socket.socket()
     self.sock.bind(address)
     self.sock.setblocking(0)
     self.sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1)
     #self.address = self.sock.getsockname()
     self.loop = pyev.default_loop()
     self.watchers = [pyev.Signal(sig, self.loop, self.signal_cb)\
                 for sig in STOPSIGNAL]
     self.watchers.append(pyev.Io(self.sock,pyev.EV_READ,self.loop, self.io_cb))
开发者ID:Monk-Liu,项目名称:Python-Server,代码行数:11,代码来源:ServerTwo.py

示例10: __init__

        def __init__(self, logger=None):
            #self._loop = pyev.default_loop(io_interval=timeout/1000.0, timeout_interval=timeout/1000.0)
            #self._loop = pyev.default_loop(timeout_interval=timeout)
            self._loop = pyev.default_loop()
            self._timer = pyev.Timer(0.01, 0, self._loop, self._timer_callback)
            self._timeout = 100
#            print self._loop.backend, pyev.EVBACKEND_EPOLL
            self._watchers = dict()  # key is fd
            self._empty = []
            self.logger = logger
            self._in = pyev.EV_READ
            self._out = pyev.EV_WRITE
开发者ID:42qu,项目名称:vps,代码行数:12,代码来源:io_poll.py

示例11: __init__

    def __init__(self, hooks):
        self.sequenceid = None
        self._need_synch = False
        self.indata = None
        self.outdata = ''

        self.hooks = hooks

        loop = pyev.default_loop()
        self.watcher = pyev.Io(self._file.fileno(), pyev.EV_READ, loop,
                self.io, self)
        self.watcher.start()
开发者ID:ITI,项目名称:rscadstreamer,代码行数:12,代码来源:rscad.py

示例12: main

def main():
    loop = pyev.default_loop()
    
    signal_handler = whizzer.signal_handler(loop)
    signal_handler.start()
    
    factory = HTTPProtocolFactory()
    server = whizzer.TcpServer(loop, factory, "127.0.0.1", 2000, 256)

    signal_handler.start()
    server.start()

    loop.loop()
开发者ID:bfrog,项目名称:whizzer,代码行数:13,代码来源:httpserver.py

示例13: __init__

 def __init__(self, bind_host, handler):
     register.handler = handler
     self.bind_host = bind_host
     self.connections = {}
     self.loop = pyev.default_loop()
     self.watchers = [pyev.Signal(sig, self.loop, self.signal_cb) for sig in STOPSIGNALS]
     # create the socket and bind
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     self.sock.bind(bind_host)
     self.sock.setblocking(0)
     # create the watcher that listens for new connections
     self.listen_watcher = pyev.Io(self.sock, pyev.EV_READ, self.loop, self.io_cb)
开发者ID:nemiliani,项目名称:pywebev,代码行数:13,代码来源:server.py

示例14: init

    def init(self, args):

        self.current = 0


        debug('init')

        l = pyev.default_loop()
        self.timer = pyev.Timer(30.0, 30.0, l, self.do_timer)
        self.timer.start()

        return {
            'output': self.do_output,
        }
开发者ID:ITI,项目名称:rscadstreamer,代码行数:14,代码来源:autobreak.py

示例15: connect

def connect(address, port=24414):
    global config, connection_map
    name, public_key, secret_key = load_identity()
    if name is not None:
        print("Your identity is:")
        print(name + " " + get_fingerprint(public_key))
        print("Verify this fingerprint is valid when connecting")
    else:
        name, public_key, secret_key = new_key_interface()
    config = configparser.RawConfigParser()
    config.read("netshrink.cfg")
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    loop = pyev.default_loop()
    connection_map[0] = Connection(sock, (address, port))
开发者ID:k3d3,项目名称:NetShrink,代码行数:14,代码来源:netshrink.py


注:本文中的pyev.default_loop函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。