2

cat t.py

import threading
import sys

class RecoverKey(threading.Thread):
    cond = threading.Condition()
    def __init__(self, idx=0):
        threading.Thread.__init__(self)
        self.idx = idx
    def run(self):
        for i in range(5):
            self.cond.acquire()
            print(self.idx * 10)
            sys.stdout.flush()
            self.idx *= 10
            self.cond.release()

if __name__ == '__main__':
    for i in range(1, 3):
        r = RecoverKey(i)
        r.start()

:~/test>python t.py 

10

20
100
200
1000
2000
10000
20000
100000
200000

Why there is one more line between '10' and '20'?

And sometime it may disappear..

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
hello.co
  • 746
  • 3
  • 21

1 Answers1

0

I would check out these two questions, which deal with the same issue. I'm not sure why it's happening, but it looks like replacing print x with print >> sys.stderr, x works (tried it).

Community
  • 1
  • 1
samGbos
  • 867
  • 1
  • 6
  • 13