Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Bridge (more inline with how node works) #100

Closed
wants to merge 0 commits into from

Conversation

prologic
Copy link
Member

No description provided.

@landscape-bot
Copy link

Code Health
Repository health increased by 0.04% when pulling 03dac08 on improved-bridge into 53aebc8 on fix_bridge_cleanup.

@prologic
Copy link
Member Author

This changes the Bridge usage a bit:

  • Removes implicit event traversal.
  • Events are now explicitly sent to a subprocess.

Usage:

from __future__ import print_function

from os import getpid


from circuits import child, Event, Component


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


class Child(Component):

    def hello(self):
        return "Hello from child with pid {0}".format(getpid())


class App(Component):

    def init(self):
        Child().start(process=True, link=self)

    def ready(self, *args):
        x = yield self.call(hello())
        yield print(x)

        y = yield self.call(child(hello()))
        yield print(y)

        raise SystemExit(0)

    def hello(self):
        return "Hello from parent with pid {0}".format(getpid())


App().run()

Output:

$ python test_bridge.py
Hello from parent with pid 814
Hello from child with pid 817

@landscape-bot
Copy link

Code Health
Repository health increased by 0.04% when pulling 1f93989 on improved-bridge into 53aebc8 on fix_bridge_cleanup.

@landscape-bot
Copy link

Code Health
Repository health increased by 0.04% when pulling 584fdff on improved-bridge into 53aebc8 on fix_bridge_cleanup.

@prologic
Copy link
Member Author

This also works with multiple subprocesses:

Example:

from __future__ import print_function

from os import getpid


from circuits import child, Event, Component


class go(Event):
    """go Event"""


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


class Child(Component):

    def hello(self):
        return "Hello from child with pid {0}".format(getpid())


class App(Component):

    def init(self):
        self.counter = 0
        self.child1 = Child().start(process=True, link=self)
        self.child2 = Child().start(process=True, link=self)

    def ready(self, *args):
        self.counter += 1
        if self.counter < 2:
            return
        self.fire(go())

    def go(self):
        x = yield self.call(hello())
        yield print(x)

        y = yield self.call(child(hello()), self.child1[1].channel)
        yield print(y)

        z = yield self.call(child(hello()), self.child2[1].channel)
        yield print(z)

        raise SystemExit(0)

    def hello(self):
        return "Hello from parent with pid {0}".format(getpid())


App().run()

Output:

$ python examples/hello_bridge.py
Hello from parent with pid 1733
Hello from child with pid 1736
Hello from child with pid 1737

@landscape-bot
Copy link

Code Health
Repository health increased by 0.06% when pulling 8430985 on improved-bridge into 53aebc8 on fix_bridge_cleanup.

@prologic
Copy link
Member Author

/cc @spaceone @treemo @circuits/developers Need some input/feedback on this one :) These are breaking API changes on Bridge; but I don't think it's ever been used very much likely because of it's poor design/API in the first place :) I think it's a lot more useful now!

@landscape-bot
Copy link

Code Health
Repository health increased by 0.06% when pulling e5c6aba on improved-bridge into fe2e7e0 on bug-fix#51.

@prologic
Copy link
Member Author

bump!

@prologic
Copy link
Member Author

I want to get this merged in pretty quckly so speak y'all :) I have a use-case for this improved bridge in oss6/statico#12

@treemo
Copy link
Contributor

treemo commented Jun 17, 2015

@prologic I never use the bridge (I use node for dispatch the events on process / host)

@prologic
Copy link
Member Author

@treemo Yeah that's cool! I tried to modify the bridge such that it has a very similar API and usage to Node :) What do you think anyway?

@spaceone
Copy link
Contributor

I'll give my feedback in the evening (in german time zone).

@landscape-bot
Copy link

Code Health
Repository health increased by 0.09% when pulling 5449fd3 on improved-bridge into fe2e7e0 on bug-fix#51.

@spaceone
Copy link
Contributor

I think the change is really nice, i like explicity... But I don't like the event name child. I currently can't think of which name suits better.

@prologic
Copy link
Member Author

The reason I called it child() was the following connotations:

  • Let's fire a remote event foo to host:port
  • Let's fire a child event foo to uuid

@prologic
Copy link
Member Author

@ALL Okay so we could call the event ipc() if that makes more sense?

Was just thinking about this; you could also message the parent, not just the child. For example in pingpong.py

@prologic
Copy link
Member Author

Bump :)

Also see: https://gist.github.com/prologic/7bb5bbcecfb79bfdc841

Just playing around here... Could turn into something more concrete!

@landscape-bot
Copy link

Code Health
Repository health increased by 0.09% when pulling cd83397 on improved-bridge into fe2e7e0 on bug-fix#51.

@prologic
Copy link
Member Author

bump

@prologic prologic force-pushed the master branch 2 times, most recently from 26d4545 to 68a6a8d Compare July 3, 2015 00:33
@landscape-bot
Copy link

Code Health
Repository health increased by 0.12% when pulling cd83397 on improved-bridge into 68a6a8d on master.

@prologic prologic self-assigned this Jul 5, 2015
@prologic prologic added this to the next milestone Jul 14, 2015
@prologic
Copy link
Member Author

I'm going to rename the event to ipc() and merge this!

@prologic prologic closed this Jul 24, 2015
@prologic prologic deleted the improved-bridge branch August 17, 2015 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants