creating generators from function

2004-12-08 Thread Simon Wittber
I use a coroutine/generator framework for simulating concurrent processes. To do this, I write all my functions using the general form: while True: do stuff yield None To make these generator functions compatible with a standard thread interface, I attempted to write a decorator which co

Re: creating generators from function

2004-12-08 Thread Steven Bethard
Simon Wittber wrote: I use a coroutine/generator framework for simulating concurrent processes. To do this, I write all my functions using the general form: while True: do stuff yield None To make these generator functions compatible with a standard thread interface, I attempted to write a

Re: creating generators from function

2004-12-08 Thread Peter Otten
Simon Wittber wrote: > I use a coroutine/generator framework for simulating concurrent processes. > > To do this, I write all my functions using the general form: > > while True: > do stuff > yield None > > To make these generator functions compatible with a standard thread > interface, I attem

Re: creating generators from function

2004-12-08 Thread Simon Wittber
> I'm a little confused as to what you're trying to do here. The f() > function, in particular, doesn't make much sense I see I am misunderstood. The example was contrived, and it seems, incorrect. I simulate threads, using generator functions and a scheduler. My implementation lives here: http

Re: creating generators from function

2004-12-08 Thread Timo Virkkala
Simon Wittber wrote: I guess this changes my question to: Can I convert a function containing an infinite loop, into a generator which will yield on each iteration? Why don't you just use threads? It would probably be easier in the long run... -- Timo Virkkala -- http://mail.python.org/mailman/lis

Re: creating generators from function

2004-12-08 Thread Terry Reedy
"Simon Wittber" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I guess this changes my question to: Can I convert a function > containing an infinite loop, into a generator which will yield on each > iteration? A function containing an infinite loop will never return, so it is bug

Re: creating generators from function

2004-12-08 Thread Simon Wittber
> A function containing an infinite loop will never return, so it is bugged > and useless unless it does has an external effect with something like > 'print xxx' within the loop. I thought the idiom: while True: #code which iterates my simulation if condition: break wat quite normal. T

Re: creating generators from function

2004-12-08 Thread Terry Reedy
"Simon Wittber" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I thought the idiom: > > while True: >#code which iterates my simulation >if condition: break > > wat quite normal. This is the style loop I am using. Yes, quite normal. This is Python's version of do...until,

Re: creating generators from function

2004-12-08 Thread Mike Meyer
Simon Wittber <[EMAIL PROTECTED]> writes: >> A function containing an infinite loop will never return, so it is bugged >> and useless unless it does has an external effect with something like >> 'print xxx' within the loop. > > I thought the idiom: > > while True: > #code which iterates my s

Re: creating generators from function

2004-12-08 Thread Isaac To
> "Mike" == Mike Meyer <[EMAIL PROTECTED]> writes: Mike> I think it's a bit abnormal, because you have to scan the Mike> loop body for breaks. I tend to write: Mike> condition = True Mike> while condition: # corrected Mike> #code which iterates my simulation Then you

Re: creating generators from function

2004-12-09 Thread Mike Meyer
Isaac To <[EMAIL PROTECTED]> writes: >> "Mike" == Mike Meyer <[EMAIL PROTECTED]> writes: > > Mike> I think it's a bit abnormal, because you have to scan the > Mike> loop body for breaks. I tend to write: > > Mike> condition = True > Mike> while condition: # corrected > Mik