Exemplo n.º 1
0
        return io_conn

    ConnectionFactory.register_construction(io_type="tcp",
                                            variant="threaded-and-logged",
                                            constructor=tcp_thd_conn)
    # -------------------------------------------------------------------

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s |%(name)-40s |%(message)s',
        datefmt='%H:%M:%S',
        stream=sys.stderr,
    )
    connections2observe4ip = [(('localhost', 5671), '10.0.2.15'),
                              (('localhost', 5672), '10.0.2.16')]
    servers = start_ping_servers(connections2observe4ip)
    main(connections2observe4ip)
    stop_ping_servers(servers)
'''
LOG OUTPUT

15:45:31 |threaded.ping.tcp-server(5671)           |Ping Sim started at tcp://localhost:5671
15:45:31 |threaded.ping.tcp-server(5672)           |Ping Sim started at tcp://localhost:5672
15:45:31 |moler.runner.thread-pool                 |created
15:45:31 |moler.runner.thread-pool                 |created own executor <concurrent.futures.thread.ThreadPoolExecutor object at 0x0000000002E35320>
15:45:31 |moler.runner.thread-pool                 |created
15:45:31 |moler.runner.thread-pool                 |created
15:45:31 |moler.runner.thread-pool                 |created own executor <concurrent.futures.thread.ThreadPoolExecutor object at 0x0000000002E35710>
15:45:31 |moler.runner.thread-pool                 |created own executor <concurrent.futures.thread.ThreadPoolExecutor object at 0x0000000002E357F0>
15:45:31 |moler.runner.thread-pool                 |created
15:45:31 |moler.user.app-code                      |observe 10.0.2.15 on tcp://localhost:5671 using NetworkDownDetector(id:2e35240)
Exemplo n.º 2
0
    # Configure moler connections (backend code)
    # 1) configure variant by YAML config file
    # 2) ver.2 - configure named connections by YAML config file
    load_config(config=os.path.join(os.path.dirname(__file__), "..",
                                    "named_connections.yml"))

    # 3) take default class used to realize tcp-threaded-connection
    # -------------------------------------------------------------------

    configure_logging()

    net_1 = ('localhost', 5671)
    net_2 = ('localhost', 5672)
    connections2serve = [(net_1, '10.0.2.15'), (net_2, '10.0.2.16')]
    connections2observe4ip = [('net_1', '10.0.2.15'), ('net_2', '10.0.2.16')]
    servers = start_ping_servers(connections2serve)
    try:
        main(connections2observe4ip)
    finally:
        stop_ping_servers(servers)
'''
LOG OUTPUT

15:28:23 |threaded.ping.tcp-server(5671)                |   MainThread |Ping Sim started at tcp://localhost:5671
15:28:23 |threaded.ping.tcp-server(5672)                |   MainThread |Ping Sim started at tcp://localhost:5672
15:28:23 |asyncio.main                                  |   MainThread |starting jobs observing connections
15:28:23 |moler.runner.asyncio-in-thrd:0                |     Thread-3 |created AsyncioInThreadRunner:139990601181112
15:28:23 |moler.user.app-code                           |     Thread-3 |observe 10.0.2.15 on tcp://localhost:5671 using NetworkDownDetector(id:7f521a0e27f0)
15:28:23 |moler.runner.asyncio-in-thrd:7f521a0e27f0     |     Thread-3 |go background: NetworkDownDetector(id:7f521a0e27f0, using ThreadedMolerConnection(id:7f521a0e2470)-->[<bound method Tcp.send of <moler.io.raw.tcp.ThreadedTcp object at 0x7f521a0e2630>>])
15:28:23 |asyncio                                       |     Thread-3 |Using selector: EpollSelector
15:28:23 |moler.runner.asyncio-in-thrd:7f521a0e27f0     |     Thread-3 |created loop 4 thread: 139990601182008:<_UnixSelectorEventLoop running=False closed=False debug=False>
Exemplo n.º 3
0
        format='%(asctime)s |%(name)25s |%(message)s',
        datefmt='%H:%M:%S',
        stream=sys.stderr,
    )
    # --------------------------------------------------------------------
    import platform
    import selectors
    selector = selectors.DefaultSelector()
    if platform.system() == 'Windows':
        # need workaround:   https://github.com/dabeaz/curio/issues/75
        import socket as stdlib_socket
        dummy_socket = stdlib_socket.socket(stdlib_socket.AF_INET,
                                            stdlib_socket.SOCK_DGRAM)
        selector.register(dummy_socket, selectors.EVENT_READ)
    # --------------------------------------------------------------------
    servers = start_ping_servers([(('localhost', 5679), '10.0.2.15')])
    curio.run(main, 'localhost', 5679, selector=selector)
    stop_ping_servers(servers)
'''
LOG OUTPUT

16:57:07 |    curio.ping.tcp-server |Ping Sim started at tcp://:5679
16:57:07 |    curio.ping.tcp-server |WARNING - I'll be tired too much just after first client!
16:57:07 |      moler.user.app-code |waiting for data to observe
16:57:07 |     curio.tcp-connection |... connecting to tcp://:5679
16:57:09 |    curio.ping.tcp-server |connection accepted - client at tcp://192.168.56.1:56578
16:57:09 |     curio.tcp-connection |<<< b'\n'
16:57:10 |     curio.tcp-connection |<<< b'greg@debian:~$ ping 10.0.2.15\n'
16:57:11 |     curio.tcp-connection |<<< b'PING 10.0.2.15 (10.0.2.15) 56(84) bytes of data.\n'
16:57:12 |     curio.tcp-connection |<<< b'64 bytes from 10.0.2.15: icmp_req=1 ttl=64 time=0.080 ms\n'
16:57:13 |     curio.tcp-connection |<<< b'64 bytes from 10.0.2.15: icmp_req=2 ttl=64 time=0.037 ms\n'
Exemplo n.º 4
0
        writer.close()


# ==============================================================================
if __name__ == '__main__':
    from threaded_ping_server import start_ping_servers, stop_ping_servers

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s |%(name)40s |%(message)s',
        datefmt='%H:%M:%S',
        stream=sys.stderr,
    )
    event_loop = asyncio.get_event_loop()
    server_address = ('127.0.0.1', 5678)
    servers = start_ping_servers([(server_address, '10.0.2.15')])
    try:
        event_loop.run_until_complete(ping_observing_task(server_address))
    finally:
        stop_ping_servers(servers)
        event_loop.close()
'''
LOG OUTPUT

16:56:30 |                  asyncio |Using selector: SelectSelector
16:56:30 |  asyncio.ping.tcp-server |Ping Sim started at tcp://127.0.0.1:5678
16:56:30 |  asyncio.ping.tcp-server |WARNING - I'll be tired too much just after first client!
16:56:30 |      moler.user.app-code |waiting for data to observe
16:56:30 |   asyncio.tcp-connection |... connecting to tcp://127.0.0.1:5678
16:56:30 |  asyncio.ping.tcp-server |connection accepted - client at tcp://127.0.0.1:56556
16:56:30 |   asyncio.tcp-connection |<<< b'\n'
Exemplo n.º 5
0
    client_thread.start()
    client_thread.join()


# ==============================================================================
if __name__ == '__main__':
    from threaded_ping_server import start_ping_servers, stop_ping_servers

    logging.basicConfig(
        level=logging.DEBUG,
        format='%(asctime)s |%(name)25s |%(message)s',
        datefmt='%H:%M:%S',
        stream=sys.stderr,
    )
    local_address = ('localhost', 5670)
    servers = start_ping_servers([(local_address, '10.0.2.15')])
    main(local_address)
    stop_ping_servers(servers)
'''
LOG OUTPUT

16:58:04 | threaded.ping.tcp-server |Ping Sim started at tcp://localhost:5670
16:58:04 | threaded.ping.tcp-server |WARNING - I'll be tired too much just after first client!
16:58:04 |      moler.user.app-code |waiting for data to observe
16:58:04 |  threaded.tcp-connection |... connecting to tcp://localhost:5670
16:58:04 | threaded.ping.tcp-server |connection accepted - client at tcp://127.0.0.1:56582
16:58:04 |  threaded.tcp-connection |<<< b'\n'
16:58:05 |  threaded.tcp-connection |<<< b'greg@debian:~$ ping 10.0.2.15\n'
16:58:06 |  threaded.tcp-connection |<<< b'PING 10.0.2.15 (10.0.2.15) 56(84) bytes of data.\n'
16:58:07 |  threaded.tcp-connection |<<< b'64 bytes from 10.0.2.15: icmp_req=1 ttl=64 time=0.080 ms\n'
16:58:08 |  threaded.tcp-connection |<<< b'64 bytes from 10.0.2.15: icmp_req=2 ttl=64 time=0.037 ms\n'