Ejemplo n.º 1
0
def main():
    event_engine = Engine()
    node = Node(node_name="[email protected]", cookie="COOKIE", engine=event_engine)

    #
    # 1. Create a process P1
    #   Send a message to process example6 on the Erlang node with "test_link"
    #   command. This will spawn an Erlang process and tell us the pid.
    #   Reply from Erlang node will trigger next steps above in ExampleProcess6
    #
    p1 = LinkExample6()

    LOG.info("Sending {example6, test_link, %s} to remote 'example6'" %
             p1.pid_)
    remote_receiver_name = (Atom('[email protected]'), Atom("example6"))
    node.send(sender=p1.pid_,
              receiver=remote_receiver_name,
              message=(Atom("example6"), Atom("test_link"), p1.pid_))

    sleep_sec = 5
    LOG.info("Sleep %d sec" % sleep_sec)
    event_engine.sleep(sleep_sec)

    #
    # 3. End, sending a stop message
    #
    LOG.info(color("Stopping remote loop", fg="red"))
    node.send(sender=p1.pid_,
              receiver=remote_receiver_name,
              message=(Atom("example6"), Atom("stop")))

    event_engine.sleep(sleep_sec)
    node.destroy()
    LOG.error("Done")
def main():
    event_engine = Engine()
    node = Node(node_name="[email protected]", cookie="COOKIE", engine=event_engine)

    #
    # 1. At the same time as P1 (they should not interfere) create a process P2
    #   Send a message to process example7 on the Erlang node with "test_monitor"
    #   command. This will spawn an Erlang process and tell us the pid.
    #   Reply from Erlang node will trigger next steps above in ExampleProcess6
    #
    proc = MonitorExample7(node)

    LOG.info("Sending {example7, test_monitor, %s} to remote 'example7'" %
             proc.pid_)
    remote_receiver_name = (Atom('[email protected]'), Atom("example7"))
    node.send(sender=proc.pid_,
              receiver=remote_receiver_name,
              message=(Atom("example7"), Atom("test_monitor"), proc.pid_))

    sleep_sec = 5
    LOG.info("Sleep %d sec" % sleep_sec)
    event_engine.sleep(sleep_sec)

    #
    # 3. End, sending a stop message
    #
    LOG.info(color("Stopping remote loop", fg="red"))
    node.send(sender=proc.pid_,
              receiver=remote_receiver_name,
              message=(Atom("example7"), Atom("stop")))

    event_engine.sleep(sleep_sec)
    node.destroy()
    LOG.error("Done")
Ejemplo n.º 3
0
def main():
    event_engine = Engine()
    node = Node(node_name="[email protected]", cookie="COOKIE", engine=event_engine)

    MyProcess(node)

    event_engine.run_forever()
Ejemplo n.º 4
0
def main():
    event_engine = Engine()
    node = Node(node_name="[email protected]", cookie="COOKIE", engine=event_engine)

    fake_pid = node.register_new_process()

    # To be able to send to Erlang shell by name first give it a registered
    # name: `erlang:register(shell, self()).`
    # To see an incoming message in shell: `flush().`
    node.send(sender=fake_pid,
              receiver=(Atom('[email protected]'), Atom('shell')),
              message=Atom('hello'))

    event_engine.run_forever()
Ejemplo n.º 5
0
def main():
    event_engine = Engine()
    node = Node(node_name="[email protected]", cookie="COOKIE", engine=event_engine)

    #
    # 1. Create a process P1
    #   Send pid of P1 to process example5 on the Erlang node with "test_link"
    #   command, it will link remotely and try to kill us and observe the
    #   results (exit signal will be returned to Erlang).
    #
    p1 = TestLinkProcess()
    LOG.info("Sending {example5, test_link, %s} to remote 'example5'" % p1.pid_)
    node.send(sender=p1.pid_, receiver=remote_receiver_name(),
              message=(Atom("example5"), Atom("test_link"), p1.pid_))

    event_engine.run_forever()
Ejemplo n.º 6
0
def main():
    event_engine = Engine()
    node = Node(node_name="[email protected]", cookie="COOKIE", engine=event_engine)

    proc = MyProcess(node)

    def task():
        node.send(sender=proc.pid_,
                         receiver=remote_receiver_name(),
                         message=(Atom("py_proxy"),
                                  Atom("init_link"),
                                  proc.pid_))

    task()

    event_engine.run_forever()
Ejemplo n.º 7
0
#!/usr/bin/env python3
from term import Atom
from pyrlang import Process, Node
from pyrlang import AsyncioEngine as Engine


class Receiver(Process):
    def __init__(self, node):
        Process.__init__(self, node.node_name_, passive=False)
        self.node = node
        self.node_name = self.node.node_name_.split("@")[0]
        self.node.register_name(self, Atom(self.node_name))
        print("Registering process - {0}".format(self.node.node_name_))

    def handle_one_inbox_message(self, msg):
        print("Received", msg)

    def process_loop(self) -> bool:
        """ Returns True to continue running. False to stop. """
        self.handle_inbox()

        return not self.is_exiting_


event_engine = Engine()
node = Node(node_name="[email protected]",
            cookie="COOKIE",
            engine=event_engine)
receiver = Receiver(node)
event_engine.run_forever()