How to collect event results from all processes?

21 views
Skip to first unread message

Mikołaj Olszewski

unread,
Jul 23, 2014, 4:05:05 PM7/23/14
to circuit...@googlegroups.com
Hi!

Probably my previous post didn't come to group so I explain again (but shorter) my problem. But first I'd like to thank all contributors for circuits - very well and easy to use asynchronous framework.

1. I'd like to run each component in its own process - no problem, just use start method with apropriate link
2. I'd like to pass event from one component to other - it seems that operation is one way and one level only: from master to linked (on first level) component
3. I'd like to collect results from all event handlers in one place - it is not possible or I do something wrong...

My example code and generated output are below.

Code:

from os import getpid

from circuits import Component, Debugger, Event, Manager, Timer


class hello(Event):
    """hello Event"""

    success = True


class App(Component):

    def hello(self, name):
        if name != 'app':
            self.fire(hello('app'))
        return "Hello {0:s} from App! ({1:d})".format(name, getpid())

    def hello_success(self, evt, result):
        print("App: {0}".format(result))


class Sub1(Component):

    def hello(self, name):
        return "Hello {0:s} from Sub1! ({1:d})".format(name, getpid())

    def hello_success(self, evt, result):
        print("Sub1: {0}".format(result))


class Sub2(Component):

    def hello(self, name):
        return "Hello {0:s} from Sub2! ({1:d})".format(name, getpid())


class SubSub(Component):

    def hello(self, name):
        return "Hello {0:s} from SubSub! ({1:d})".format(name, getpid())


class Master(Component):

    def hello_success(self, evt, result):
        print("Master: {0}".format(result))


m = Master() + Debugger()
Timer(1, hello('master'), persist=True).register(m)
a = App()
a.start(process=True, link=m)
Sub1().start(process=True, link=m)
Sub2().start(process=True, link=m)
SubSub().start(process=True, link=a)
m.run()


Output:

<registered[*] (<Debugger/* 9264:MainThread (queued=0) [S]>, <Master/* 9264:MainThread (queued=9) [R]> )>
<registered[b9e84339-7972-42b8-944b-29333df80540] (<UNIXClient/b9e84339-7972-42b8-944b-29333df80540 9264:MainThread (queued=0) [S]>, <Bridge/b9e84339-7972-42b8-944b-29333df80540 9264:MainThread (queued=0) [S]> )>
<registered[1fe40944-9ec9-4f6e-aac7-7daf3c9f7680] (<UNIXClient/1fe40944-9ec9-4f6e-aac7-7daf3c9f7680 9264:MainThread (queued=0) [S]>, <Bridge/1fe40944-9ec9-4f6e-aac7-7daf3c9f7680 9264:MainThread (queued=0) [S]> )>
<registered[*] (<Timer/* 9264:MainThread (queued=0) [S]>, <Master/* 9264:MainThread (queued=9) [R]> )>
<registered[360d3770-2545-4473-8669-79c1ab4feae2] (<UNIXClient/360d3770-2545-4473-8669-79c1ab4feae2 9264:MainThread (queued=0) [S]>, <Bridge/360d3770-2545-4473-8669-79c1ab4feae2 9264:MainThread (queued=0) [S]> )>
<registered[b9e84339-7972-42b8-944b-29333df80540] (<Bridge/b9e84339-7972-42b8-944b-29333df80540 9264:MainThread (queued=0) [S]>, <Master/* 9264:MainThread (queued=8) [R]> )>
<registered[360d3770-2545-4473-8669-79c1ab4feae2] (<Bridge/360d3770-2545-4473-8669-79c1ab4feae2 9264:MainThread (queued=0) [S]>, <Master/* 9264:MainThread (queued=7) [R]> )>
<registered[1fe40944-9ec9-4f6e-aac7-7daf3c9f7680] (<Bridge/1fe40944-9ec9-4f6e-aac7-7daf3c9f7680 9264:MainThread (queued=0) [S]>, <Master/* 9264:MainThread (queued=6) [R]> )>
<started[*] (<Master/* 9264:MainThread (queued=5) [R]> )>
<registered[select] (<Select/select 9264:MainThread (queued=0) [S]>, <UNIXClient/b9e84339-7972-42b8-944b-29333df80540 9264:MainThread (queued=0) [S]> )>
<ready[b9e84339-7972-42b8-944b-29333df80540] (<UNIXClient/b9e84339-7972-42b8-944b-29333df80540 9264:MainThread (queued=0) [S]> )>
<ready[1fe40944-9ec9-4f6e-aac7-7daf3c9f7680] (<UNIXClient/1fe40944-9ec9-4f6e-aac7-7daf3c9f7680 9264:MainThread (queued=0) [S]> )>
<ready[360d3770-2545-4473-8669-79c1ab4feae2] (<UNIXClient/360d3770-2545-4473-8669-79c1ab4feae2 9264:MainThread (queued=0) [S]> )>
<hello[*] ('master' )>
<hello_success[*] (<hello[*] ('master' )>, None )>
<_write[360d3770-2545-4473-8669-79c1ab4feae2] (<socket.socket fd=8, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
<_write[b9e84339-7972-42b8-944b-29333df80540] (<socket.socket fd=5, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
<_write[1fe40944-9ec9-4f6e-aac7-7daf3c9f7680] (<socket.socket fd=11, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
Master: None
App: Hello master from App! (9266)
Sub1: Hello master from Sub1! (9268)
App: Hello app from App! (9266)
<_read[b9e84339-7972-42b8-944b-29333df80540] (<socket.socket fd=5, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
<read[b9e84339-7972-42b8-944b-29333df80540] (b'\x80\x03\x8a\x08\x9eg\xfd\xe2\xfc\x07\x00\x80c__main__\nhello\nq\x00)\x81q\x01}q\x02(X\x07\x00\x00\x00stoppedq\x03\x89X\x08\x00\x00\x00channelsq\x04X\x01\x00\x00\x00*q\x05\x85q\x06X\t\x00\x00\x00cancelledq\x07\x89X\x05\x00\x00\x00valueq\x08ccircuits.core.values\nValue\nq\t)\x81q\n}q\x0b(X\x06\x00\x00\x00parentq\x0ch\nX\x07\x00\x00\x00handledq\r\x89X\x05\x00\x00\x00eventq\x0eh\x01X\x06\x00\x00\x00resultq\x0f\x89X\x07\x00\x00\x00promiseq\x10\x89X\x06\x00\x00\x00_valueq\x11NX\x06\x00\x00\x00notifyq\x12\x89X\x06\x00\x00\x00errorsq\x13\x89ubh\x12X\r\x00\x00\x00value_changedq\x14X\x03\x00\x00\x00uidq\x15NX\x06\x00\x00\x00kwargsq\x16}q\x17X\x04\x00\x00\x00argsq\x18]q\x19X\x03\x00\x00\x00appq\x1aaX\x04\x00\x00\x00nameq\x1bX\x05\x00\x00\x00helloq\x1cub\x86q\x1d.\x80\x03\x8a\x06\x16\xcf,\xe3\xfc\x07ccircuits.core.values\nValue\nq\x00)\x81q\x01}q\x02(X\x06\x00\x00\x00parentq\x03h\x01X\x07\x00\x00\x00handledq\x04\x89X\x05\x00\x00\x00eventq\x05c__main__\nhello\nq\x06)\x81q\x07}q\x08(X\x05\x00\x00\x00valueq\th\x01X\x07\x00\x00\x00stoppedq\n\x89X\x04\x00\x00\x00nameq\x0bX\x05\x00\x00\x00helloq\x0cX\t\x00\x00\x00cancelledq\r\x89X\x04\x00\x00\x00argsq\x0e]q\x0fX\x06\x00\x00\x00masterq\x10aX\x06\x00\x00\x00notifyq\x11X\r\x00\x00\x00value_changedq\x12X\x03\x00\x00\x00uidq\x13NX\x06\x00\x00\x00kwargsq\x14}q\x15X\x06\x00\x00\x00remoteq\x16\x88X\x08\x00\x00\x00channelsq\x17X\x01\x00\x00\x00*q\x18\x85q\x19ubX\x06\x00\x00\x00resultq\x1a\x88X\x07\x00\x00\x00promiseq\x1b\x89X\x06\x00\x00\x00_valueq\x1cX\x1d\x00\x00\x00Hello master from App! (9266)q\x1dX\x06\x00\x00\x00notifyq\x1e\x89X\x06\x00\x00\x00errorsq\x1f\x89ub\x86q .' )>
<_read[360d3770-2545-4473-8669-79c1ab4feae2] (<socket.socket fd=8, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
<read[360d3770-2545-4473-8669-79c1ab4feae2] (b'\x80\x03\x8a\x06\x16\xcf,\xe3\xfc\x07ccircuits.core.values\nValue\nq\x00)\x81q\x01}q\x02(X\x06\x00\x00\x00parentq\x03h\x01X\x07\x00\x00\x00handledq\x04\x89X\x05\x00\x00\x00eventq\x05c__main__\nhello\nq\x06)\x81q\x07}q\x08(X\x05\x00\x00\x00valueq\th\x01X\x07\x00\x00\x00stoppedq\n\x89X\x04\x00\x00\x00nameq\x0bX\x05\x00\x00\x00helloq\x0cX\t\x00\x00\x00cancelledq\r\x89X\x04\x00\x00\x00argsq\x0e]q\x0fX\x06\x00\x00\x00masterq\x10aX\x06\x00\x00\x00notifyq\x11X\r\x00\x00\x00value_changedq\x12X\x03\x00\x00\x00uidq\x13NX\x06\x00\x00\x00kwargsq\x14}q\x15X\x06\x00\x00\x00remoteq\x16\x88X\x08\x00\x00\x00channelsq\x17X\x01\x00\x00\x00*q\x18\x85q\x19ubX\x06\x00\x00\x00resultq\x1a\x88X\x07\x00\x00\x00promiseq\x1b\x89X\x06\x00\x00\x00_valueq\x1cX\x1e\x00\x00\x00Hello master from Sub1! (9268)q\x1dX\x06\x00\x00\x00notifyq\x1e\x89X\x06\x00\x00\x00errorsq\x1f\x89ub\x86q .' )>
<_read[1fe40944-9ec9-4f6e-aac7-7daf3c9f7680] (<socket.socket fd=11, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
<read[1fe40944-9ec9-4f6e-aac7-7daf3c9f7680] (b'\x80\x03\x8a\x06\x16\xcf,\xe3\xfc\x07ccircuits.core.values\nValue\nq\x00)\x81q\x01}q\x02(X\x06\x00\x00\x00parentq\x03h\x01X\x07\x00\x00\x00handledq\x04\x89X\x05\x00\x00\x00eventq\x05c__main__\nhello\nq\x06)\x81q\x07}q\x08(X\x05\x00\x00\x00valueq\th\x01X\x07\x00\x00\x00stoppedq\n\x89X\x04\x00\x00\x00nameq\x0bX\x05\x00\x00\x00helloq\x0cX\t\x00\x00\x00cancelledq\r\x89X\x04\x00\x00\x00argsq\x0e]q\x0fX\x06\x00\x00\x00masterq\x10aX\x06\x00\x00\x00notifyq\x11X\r\x00\x00\x00value_changedq\x12X\x03\x00\x00\x00uidq\x13NX\x06\x00\x00\x00kwargsq\x14}q\x15X\x06\x00\x00\x00remoteq\x16\x88X\x08\x00\x00\x00channelsq\x17X\x01\x00\x00\x00*q\x18\x85q\x19ubX\x06\x00\x00\x00resultq\x1a\x88X\x07\x00\x00\x00promiseq\x1b\x89X\x06\x00\x00\x00_valueq\x1cX\x1e\x00\x00\x00Hello master from Sub2! (9270)q\x1dX\x06\x00\x00\x00notifyq\x1e\x89X\x06\x00\x00\x00errorsq\x1f\x89ub\x86q .' )>
<hello[*] ('master' )>
Master: None
<hello_success[*] (<hello[*] ('master' )>, None )>
Sub1: Hello master from Sub1! (9268)
<_write[360d3770-2545-4473-8669-79c1ab4feae2] (<socket.socket fd=8, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
App: Hello master from App! (9266)
<_write[b9e84339-7972-42b8-944b-29333df80540] (<socket.socket fd=5, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
App: Hello app from App! (9266)
<_write[1fe40944-9ec9-4f6e-aac7-7daf3c9f7680] (<socket.socket fd=11, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
<_read[360d3770-2545-4473-8669-79c1ab4feae2] (<socket.socket fd=8, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
<read[360d3770-2545-4473-8669-79c1ab4feae2] (b'\x80\x03\x8a\x06\x16\xcf,\xe3\xfc\x07ccircuits.core.values\nValue\nq\x00)\x81q\x01}q\x02(X\x06\x00\x00\x00parentq\x03h\x01X\x07\x00\x00\x00handledq\x04\x89X\x05\x00\x00\x00eventq\x05c__main__\nhello\nq\x06)\x81q\x07}q\x08(X\x05\x00\x00\x00valueq\th\x01X\x07\x00\x00\x00stoppedq\n\x89X\x04\x00\x00\x00nameq\x0bX\x05\x00\x00\x00helloq\x0cX\t\x00\x00\x00cancelledq\r\x89X\x04\x00\x00\x00argsq\x0e]q\x0fX\x06\x00\x00\x00masterq\x10aX\x06\x00\x00\x00notifyq\x11X\r\x00\x00\x00value_changedq\x12X\x03\x00\x00\x00uidq\x13NX\x06\x00\x00\x00kwargsq\x14}q\x15X\x06\x00\x00\x00remoteq\x16\x88X\x08\x00\x00\x00channelsq\x17X\x01\x00\x00\x00*q\x18\x85q\x19ubX\x06\x00\x00\x00resultq\x1a\x88X\x07\x00\x00\x00promiseq\x1b\x89X\x06\x00\x00\x00_valueq\x1cX\x1e\x00\x00\x00Hello master from Sub1! (9268)q\x1dX\x06\x00\x00\x00notifyq\x1e\x89X\x06\x00\x00\x00errorsq\x1f\x89ub\x86q .' )>
<_read[b9e84339-7972-42b8-944b-29333df80540] (<socket.socket fd=5, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
<_read[1fe40944-9ec9-4f6e-aac7-7daf3c9f7680] (<socket.socket fd=11, family=AddressFamily.AF_UNIX, type=2049, proto=0> )>
<read[b9e84339-7972-42b8-944b-29333df80540] (b'\x80\x03\x8a\x06qo\xfd\xe2\xfc\x07c__main__\nhello\nq\x00)\x81q\x01}q\x02(X\x07\x00\x00\x00stoppedq\x03\x89X\x08\x00\x00\x00channelsq\x04X\x01\x00\x00\x00*q\x05\x85q\x06X\t\x00\x00\x00cancelledq\x07\x89X\x05\x00\x00\x00valueq\x08ccircuits.core.values\nValue\nq\t)\x81q\n}q\x0b(X\x06\x00\x00\x00parentq\x0ch\nX\x07\x00\x00\x00handledq\r\x89X\x05\x00\x00\x00eventq\x0eh\x01X\x06\x00\x00\x00resultq\x0f\x89X\x07\x00\x00\x00promiseq\x10\x89X\x06\x00\x00\x00_valueq\x11NX\x06\x00\x00\x00notifyq\x12\x89X\x06\x00\x00\x00errorsq\x13\x89ubh\x12X\r\x00\x00\x00value_changedq\x14X\x03\x00\x00\x00uidq\x15NX\x06\x00\x00\x00kwargsq\x16}q\x17X\x04\x00\x00\x00argsq\x18]q\x19X\x03\x00\x00\x00appq\x1aaX\x04\x00\x00\x00nameq\x1bX\x05\x00\x00\x00helloq\x1cub\x86q\x1d.\x80\x03\x8a\x06\x16\xcf,\xe3\xfc\x07ccircuits.core.values\nValue\nq\x00)\x81q\x01}q\x02(X\x06\x00\x00\x00parentq\x03h\x01X\x07\x00\x00\x00handledq\x04\x89X\x05\x00\x00\x00eventq\x05c__main__\nhello\nq\x06)\x81q\x07}q\x08(X\x05\x00\x00\x00valueq\th\x01X\x07\x00\x00\x00stoppedq\n\x89X\x04\x00\x00\x00nameq\x0bX\x05\x00\x00\x00helloq\x0cX\t\x00\x00\x00cancelledq\r\x89X\x04\x00\x00\x00argsq\x0e]q\x0fX\x06\x00\x00\x00masterq\x10aX\x06\x00\x00\x00notifyq\x11X\r\x00\x00\x00value_changedq\x12X\x03\x00\x00\x00uidq\x13NX\x06\x00\x00\x00kwargsq\x14}q\x15X\x06\x00\x00\x00remoteq\x16\x88X\x08\x00\x00\x00channelsq\x17X\x01\x00\x00\x00*q\x18\x85q\x19ubX\x06\x00\x00\x00resultq\x1a\x88X\x07\x00\x00\x00promiseq\x1b\x89X\x06\x00\x00\x00_valueq\x1cX\x1d\x00\x00\x00Hello master from App! (9266)q\x1dX\x06\x00\x00\x00notifyq\x1e\x89X\x06\x00\x00\x00errorsq\x1f\x89ub\x86q .' )>
<read[1fe40944-9ec9-4f6e-aac7-7daf3c9f7680] (b'\x80\x03\x8a\x06\x16\xcf,\xe3\xfc\x07ccircuits.core.values\nValue\nq\x00)\x81q\x01}q\x02(X\x06\x00\x00\x00parentq\x03h\x01X\x07\x00\x00\x00handledq\x04\x89X\x05\x00\x00\x00eventq\x05c__main__\nhello\nq\x06)\x81q\x07}q\x08(X\x05\x00\x00\x00valueq\th\x01X\x07\x00\x00\x00stoppedq\n\x89X\x04\x00\x00\x00nameq\x0bX\x05\x00\x00\x00helloq\x0cX\t\x00\x00\x00cancelledq\r\x89X\x04\x00\x00\x00argsq\x0e]q\x0fX\x06\x00\x00\x00masterq\x10aX\x06\x00\x00\x00notifyq\x11X\r\x00\x00\x00value_changedq\x12X\x03\x00\x00\x00uidq\x13NX\x06\x00\x00\x00kwargsq\x14}q\x15X\x06\x00\x00\x00remoteq\x16\x88X\x08\x00\x00\x00channelsq\x17X\x01\x00\x00\x00*q\x18\x85q\x19ubX\x06\x00\x00\x00resultq\x1a\x88X\x07\x00\x00\x00promiseq\x1b\x89X\x06\x00\x00\x00_valueq\x1cX\x1e\x00\x00\x00Hello master from Sub2! (9270)q\x1dX\x06\x00\x00\x00notifyq\x1e\x89X\x06\x00\x00\x00errorsq\x1f\x89ub\x86q .' )>
Master: None
App: Hello master from App! (9266)
App: Hello app from App! (9266)
Sub1: Hello master from Sub1! (9268)

I'd be very thankful for any help.

--
Mikołaj Olszewski

James Mills

unread,
Jul 23, 2014, 5:14:55 PM7/23/14
to circuit...@googlegroups.com
I think this was a duplicate email because this
list is moderated (to thwart spam) :) See my reply
in the other thread :)

cheers
James

--
You received this message because you are subscribed to the Google Groups "circuits" group.
To unsubscribe from this group and stop receiving emails from it, send an email to circuits-user...@googlegroups.com.
To post to this group, send email to circuit...@googlegroups.com.
Visit this group at http://groups.google.com/group/circuits-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages