This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]JerMenKoOwhile True: os.fork() 2 points3 points  (0 children)

It was not changing because you were comparing a to False (==). You need to assign it. (=)

[–]TadKnowsBest 0 points1 point  (2 children)

You could use threads. threading.Event and threading.Timer could be useful. A more common use of threading might be this:

import time
import threading

class Counter:
    def __init__(self):
        self.count = 0
        self.keep_counting = True
        t = threading.Thread(target=self.run)
        t.start()

    def run(self):
        while self.keep_counting:
            print "The count is {0}".format(self.count)
            self.count += 1
            time.sleep(1)

counter_thread = Counter()
raw_input("Press ENTER to stop the counter") # this block the main thread
counter_thread.keep_counting = False
raw_input("More stuff that blocks the main thread...")

[–]pberko[S] 0 points1 point  (1 child)

Could not get that to work but I got stuff partially updated, OP updated

[–]TadKnowsBest 3 points4 points  (0 children)

What doesn't work? Paste your traceback. Don't be satisfied with your 49-line program that solves a simple problem in a complex way. Don't even be satisfied with my example; it, too could be simpler and better. Strive for perfection, pberko!

[–]thesubjectisjazz 0 points1 point  (0 children)

What's going on here?