Co-routines

thewrights at ozemail.com.au thewrights at ozemail.com.au
Thu Jul 17 09:39:46 EDT 2003


"Peter Hansen" <peter at engcorp.com> wrote in message
news:3F16A34A.5742F54F at engcorp.com...
> thewrights at ozemail.com.au wrote:
> >
> > I have an application in which I want the users to be able to create
python
> > functions:
> >
> > def f1():
> >     print "1-1"
> >     print "1-2"
> >     print "1-3"
> >
> > def f2():
> >     print "2-1"
> >     print "2-2"
> >     print "3-3"
> >
> > and when my application runs, I want to execute these functions in
> > "lock-step", so that the output looks like:
> >
> >     1-1
> >     2-2
> >     1-2
> >     2-2
> >     1-3
> >     2-3
>
> I think the problem is underspecified.  What do you mean by the quoted
> phrase "lock-step"?  Your example includes only simple print statements,
> which generate output to sys.stdout.  What are you really trying to
> accomplish?  Do you want individual bytecodes to be executed one at a
> time from a series of functions?  Do you want any output to be interlaced
> on a line-by-line basis?  Any call to any I/O routine?  Need more detail.
>
> -Peter

OK. Thanks.  I was just giving some simple examples...but I hope this is
better:

>From the python grammar:

    funcdef    ::= "def" funcname "(" [parameter_list] ")" ":" suite

I want the statements in <suite> to be executed on a statement by statement
basis, with no particular restrictions on *what* those statements are. It's
the execution stepping I'm interested in... the I/O in my example was just
that. I understand that there will be all the problems on contention/race
etc (just like if the functions were going in separate threads)








More information about the Python-list mailing list