Re: Pipes or Socket Help => Just use ILU!

Bill Janssen (janssen@parc.xerox.com)
Fri, 17 Mar 1995 19:14:42 PST

You could use ILU. Have each subordinate process call an asynchronous
method, when it's got something to say, on an object which is
implemented by your main process. Here's a simple example. Put
"pythonExMS.isl", "master.py", and "slave.py" in a directory somewhere.
Run the ILU "python-stubber" program against "pythonExMS.isl", thusly:

/tmp/ex1 69 % python-stubber pythonExMS
client stubs for interface "pythonExMS" to pythonExMS.py ...
server stubs for interface "pythonExMS" to pythonExMS__skel.py ...
/tmp/ex1 70 %

Then type the command "python master.py" (or, if you don't have dynamic
loading of object code, "ilu-python master.py", and watch it run...
What's happening is that the subordinate processes periodically call the
method "fromSlave" on the master object. However, instead of the
"fromSlave" method being implemented in the same address space as the
slave is running in, it is implemented by the class "realMaster", in the
master process. So whatever parameters they pass are automatically
passed to the master process, which (in the implementation of
"fromSlave") can do anything it wants with them.

ILU is available from ftp://ftp.parc.xerox.com/pub/ilu/ilu.html.

pythonExMS.isl:
----------------------------------------------------------------------
INTERFACE pythonExMS;

TYPE master = OBJECT
METHODS
ASYNCHRONOUS fromSlave (slaveID : ilu.CString, data : ilu.CString)
END;
----------------------------------------------------------------------

master.py:
----------------------------------------------------------------------
import pythonExMS__skel, os, ilu

class realMaster (pythonExMS__skel.master):

def fromSlave (self, slaveID, something):
print 'slave', slaveID, 'says: ', something

def main():

# make a master object for slave processes to report to

m = realMaster()
sbh = m.IluSBH()

# fork off a slave process

os.system ("python slave.py slave1 7 '" + sbh + "'&");
os.system ("python slave.py slave2 10 '" + sbh + "'&");
os.system ("python slave.py slave3 23 '" + sbh + "'&");

# now sit back in the ILU loop and wait for reports

ilu.RunMainLoop()

main()
----------------------------------------------------------------------

slave.py:
----------------------------------------------------------------------
import pythonExMS, ilu, time, sys, string

def do_work (m, id, period):
while 1:
time.sleep(period)
m.fromSlave (id, str(time.time()))

def main(argv):
slave_id = argv[1]
period = string.atoi (argv[2])
master = ilu.ObjectOfSBH(pythonExMS.master, argv[3])
do_work (master, slave_id, period)

if len(sys.argv) < 4:
print "Usage: python slave.py SLAVE-ID PERIOD-IN-SECONDS MASTER-SBH &"
sys.exit(1)
else:
main (sys.argv)
----------------------------------------------------------------------

Bill