Skip to content

Commit

Permalink
Renamed child() Bridge event to ipc()
Browse files Browse the repository at this point in the history
  • Loading branch information
prologic committed Jul 24, 2015
1 parent 80d988b commit f0d320b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 46 deletions.
7 changes: 4 additions & 3 deletions circuits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
from .version import version as __version__

from .core import Event
from .core import child, Bridge
from .core import ipc, Bridge
from .core import sleep, task, Worker
from .core import handler, reprhandler, BaseComponent, Component
from .core import Debugger, Loader, Manager, Timer, TimeoutError

# flake8: noqa

# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
Expand All @@ -37,3 +35,6 @@
with open(_path) as fd:
exec_(fd, globals())
del os, extend_path, _path, fd, exec_

# flake8: noqa
# pylama:skip=1
4 changes: 2 additions & 2 deletions circuits/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .events import Event
from .loader import Loader
from .bridge import child, Bridge
from .bridge import ipc, Bridge
from .handlers import handler, reprhandler
from .components import BaseComponent, Component
from .manager import sleep, Manager, TimeoutError
Expand All @@ -21,7 +21,7 @@

__all__ = (
"handler", "BaseComponent", "Component", "Event", "task",
"Worker", "Bridge", "Debugger", "Timer", "Manager", "TimeoutError",
"Worker", "ipc", "Bridge", "Debugger", "Timer", "Manager", "TimeoutError",
)

# flake8: noqa
Expand Down
40 changes: 20 additions & 20 deletions circuits/core/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
_sentinel = b('~~~')


class child(Event):
"""child Event
class ipc(Event):
"""ipc Event
Send an event to a child process
Send an event to a child/parent process
"""

def __init__(self, event, channel=None):
"""
:param event: Event to execute remotely.
:type event: :class:`circuits.core.events.Event`
:param event: Event to execute remotely.
:type event: :class:`circuits.core.events.Event`
:param channel: Remote channel (channel to use on peer).
:type channel: str
:param channel: IPC Channel (channel to use on child/parent).
:type channel: str
"""

super(child, self).__init__(event, channel=channel)
super(ipc, self).__init__(event, channel=channel)


class Bridge(BaseComponent):
Expand Down Expand Up @@ -107,18 +107,18 @@ def __send(self, eid, event):
def __write(self, eid, data):
self._socket.write(dumps((eid, data)) + _sentinel)

@handler("child")
def _on_child(self, event, child_event, channel=None):
"""Send event to a child process
@handler("ipc")
def _on_ipc(self, event, ipc_event, channel=None):
"""Send event to a child/parentprocess
Event handler to run an event on a child process
(the event definition is :class:`circuits.core.bridge.child`)
Event handler to run an event on a child/parent process
(the event definition is :class:`circuits.core.bridge.ipc`)
:param event: The event triggered (by the handler)
:type event: :class:`circuits.node.events.remote`
:param child_event: Event to execute in child process.
:type child_event: :class:`circuits.core.events.Event`
:param ipc_event: Event to execute in child/parent process.
:type ipc_event: :class:`circuits.core.events.Event`
:param channel: Remote channel (channel to use on peer).
:type channel: str
Expand All @@ -128,15 +128,15 @@ def _on_child(self, event, child_event, channel=None):
:Example:
``# hello is your event to execute in the child process
result = yield self.fire(child(hello()))
result = yield self.fire(ipc(hello()))
print(result.value)``
"""

child_event.channels = (channel,) if channel is not None else event.channels
event.value.value = child_event.value = Value(child_event, self)
ipc_event.channels = (channel,) if channel is not None else event.channels
event.value.value = ipc_event.value = Value(ipc_event, self)

eid = hash(child_event)
self.__send(eid, child_event)
eid = hash(ipc_event)
self.__send(eid, ipc_event)
yield self.wait(Bridge.__waiting_event(eid))

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions examples/hello_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from os import getpid


from circuits import child, Event, Component
from circuits import ipc, Event, Component


class hello(Event):
Expand All @@ -35,7 +35,7 @@ def ready(self, *args):
x = yield self.call(hello())
yield print(x)

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

raise SystemExit(0)
Expand Down
6 changes: 3 additions & 3 deletions examples/hello_multi_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from os import getpid


from circuits import child, Event, Component
from circuits import ipc, Event, Component


class go(Event):
Expand Down Expand Up @@ -45,10 +45,10 @@ def go(self):
x = yield self.call(hello())
yield print(x)

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

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

raise SystemExit(0)
Expand Down
23 changes: 9 additions & 14 deletions examples/pingpong.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from signal import SIGINT, SIGTERM


from circuits import child, handler, Event, Component, Timer
from circuits import ipc, handler, Event, Component


def log(msg, *args, **kwargs):
Expand All @@ -41,40 +41,35 @@ class pong(Event):
"""pong Event"""


class display(Event):
"""display Event"""


class Child(Component):

def ping(self, ts):
self.fire(child(pong(ts, time())))
self.fire(ipc(pong(ts, time())))


class App(Component):

def init(self):
self.events = 0
self.latency = 0
self.stime = time()

from circuits import Debugger
Debugger(events=False).register(self)

Child().start(process=True, link=self)
Timer(0.5, display(), persist=True).register(self)

def ready(self, *args):
self.fire(child(ping(time())))
self.fire(ipc(ping(time())))

def pong(self, ts1, ts2):
self.latency = (ts2 - ts1) * 1000.0
self.fire(child(ping(time())))

def display(self):
latency = (ts2 - ts1) * 1000.0
status(
"{0:d} event/s @ {1:0.2f}ms latency".format(
int(self.events / (time() - self.stime)),
self.latency
latency
)
)
self.fire(ipc(ping(time())))

def signal(self, signo, stack):
if signo in [SIGINT, SIGTERM]:
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from os import getpid


from circuits import child, Component, Event
from circuits import ipc, Component, Event


class hello(Event):
Expand All @@ -30,7 +30,7 @@ def test(manager, watcher):
process, bridge = app.start(process=True, link=manager)
assert watcher.wait("ready")

x = manager.fire(child(hello()))
x = manager.fire(ipc(hello()))

assert pytest.wait_for(x, "result")

Expand Down

0 comments on commit f0d320b

Please sign in to comment.