[TransWarp] input-driven application

alexander smishlajev alex at ank-sia.com
Thu May 15 16:03:18 EDT 2003


hello!

i want to build an application that is a chain of components acting like
unix filters: process input stream and produce results on the output stream.

all those components should act cooperatively, each processing a chunk
of input data as soon as it arrives.  i am able to establish
non-blocking pipes between components (but not through select: on
windows, select() works for ip sockets only).

it seems to me that peak.running.AbstractCommand is a good base for
filtering input to output.  besides, being an IExecutable, each
component is able to run per se, using shell stdin and stdout, right?
this is useful for filter debugging.

furthermore, it seems to me that peak.running.daemons.AdaptiveTask is a
good base for cooperation: each component will check it's input in
getWork() and, if some data arrived, process it in doWork(), producing
output for the next component (or the final output for the application).

now, how do i put all these things together?

i have composed a simple component:

=== begin cut Echo.py ===

from peak.api import binding
from peak.running import commands, daemons, interfaces

class Echo(commands.AbstractCommand, daemons.AdaptiveTask):

     usage = """Copy standard input to standard output

Usage: peak import:Echo.Echo
"""

     runEvery = .001

     mainLoop = binding.bindTo(interfaces.IMainLoop)

     def run(self):
         self.mainLoop.run()

     def getWork(self):
         return self.stdin.read()

     def doWork(self, job):
         self.stdout.write(job)

==== end cut Echo.py ====

and i tried to run it with 'peak import:Echo.Echo'.

that did not do anything.  where am i wrong?

best wishes,
alex.

ps.  if each filter had a handle of it's follower, i could kick that
follower by means of reactor.callLater(), but, of course, i want to
avoid explicit siblings specification in each component.






More information about the PEAK mailing list