def test_node_connect_accept(self): log = stdout_logger() params1 = NodeParams(runmode=MAIN, port=8333) params2 = NodeParams(runmode=MAIN, port=8334) node1 = Node(params1, log) node2 = Node(params2, log) node1.connect_peer(SockAddr("localhost", 8334)) node2.subscribe(Node.EVT_CONNECTED, lambda event: reactor.stop()) reactor.run()
def test_inline_callbacks_exception1(self): reactor.reset() def print_result(result=None, error=None): assert error print "error", error[0] f = asynch_fct4() f.set_callback(print_result) reactor.call_later(1, reactor.stop) reactor.run() print "stop" assert f.completed
def test_inline_callbacks(self): reactor.reset() def print_result(result=None, error=None): print "result", result assert result == 18 f = asynch_fct2() f.set_callback(print_result) reactor.call_later(0.6, reactor.stop) reactor.run() print "stop" assert f.completed
def test_cpu_bound(self): def print_result(result=None, error=None): print "result", result assert result == 2499997500000 f1 = asynch_fct1("a") f2 = asynch_fct1("b") f1.set_callback(print_result) f2.set_callback(print_result) print "start" reactor.call_later(3, reactor.stop) reactor.run() print "stop"
def test_node_send_receive_message(self): log = stdout_logger() params1 = NodeParams(runmode=MAIN, port=8335) params2 = NodeParams(runmode=MAIN, port=8336) node1 = Node(params1, log) node2 = Node(params2, log) def on_connect(event): node1.send_message(event.handler, VerackMessage()) node1.subscribe(Node.EVT_CONNECTED, on_connect) def on_message(event): assert event.message.type == MSG_VERACK reactor.stop() node2.subscribe(Node.EVT_BASIC_MESSAGE, on_message) node1.connect_peer(SockAddr("localhost", 8336)) reactor.run()
import socket from coinpy.tools.reactor.reactor import Reactor, reactor from coinpy.tools.reactor.asyncore_plugin import AsyncorePlugin class EchoHandler(asyncore.dispatcher_with_send): def handle_read(self): data = self.recv(8192) if data: self.send(data) class EchoServer(asyncore.dispatcher): def __init__(self, host, port): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.bind((host, port)) self.listen(5) def handle_accept(self): pair = self.accept() if pair is None: pass else: sock, addr = pair print 'Incoming connection from %s' % repr(addr) handler = EchoHandler(sock) server = EchoServer('localhost', 8080) reactor.install(AsyncorePlugin()) reactor.run()
from coinpy.tools.reactor.reactor import Reactor, reactor from coinpy.tools.reactor.wx_plugin import WxPlugin import wx reactor.install(WxPlugin()) frame = wx.Frame(None) frame.Show() reactor.run()
def run(self): self.view.start() reactor.run()
def run(self): self.bootstrapper.bootstrap() reactor.run()