Re: flow control / get next / filter?

From: Ken Godee (ken_at_perfect-image.com)
Date: 10/30/03


Date: Wed, 29 Oct 2003 20:04:11 -0700
To: python-list@python.org

If it was a Python, Errr.... Snake, it would have bit me.

Answer, the "Queue module"

Ken Godee wrote:
> I'm trying to figure out how to get the value of a variable
> that's constantly getting updated, but only get the new
> value, once it has changed.
>
> I have a module where I register a call back to a function
> in the code I'm working on. This function gets updated continuely.
> ie....
>
> x = ''
> def myfunc(event)
> global x
> x = event
>
> if you where to do a while loop, you would end up with something like...
>
> while 1:
> print x
> if x == 'stop':
> break
>
> 1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,
>
> if you where to do a nested while, you would get....
>
> while 1:
> print x
> while x != x:
> print x
> if x == 'stop':
> break
> if x == 'stop':
> break
>
> 1,2,3,4,5
>
> but it of coarse just spins the loop and processor loads pegs out.
>
> If someone could point me in a direction, I'd appreciate it.
> Thanks
>
>
>



Relevant Pages

  • Re: Python un-plugging the Interpreter
    ... Perhaps the current wave of dual-core and quad-core CPUs in cheap ... Python and use algorithms that are possible to parallellize? ... from my own attitude - getting a thread running was one of the ... *grin* before I discovered the queue module, ...
    (comp.lang.python)
  • Re: noob import question
    ... (do you mean Queue module, ... I recommend avoiding it. ... the Python library isn't setting a good example here. ...
    (comp.lang.python)
  • Re: What is the best queue implemetation in Python?
    ... list or dictionary in Python are so powerful than the traditional ... Well, you could wite your own queue manager using Python lists, ... Or perhaps you want/need the Queue module or the heapq module. ...
    (comp.lang.python)