2

I have a large system with workers and manager threads.

I have run into the problem that one of the threads uses:

print "before time sleep"
time.sleep(5)
print "after time sleep"

It will print both a lot of times and then suddenly only display "before time sleep" And stop until i kill all the other threads. None of the other threads are stopping.

I think some other part of the code is locking the commandline output or something like that, but I have no idea how to find the spot (it can take up to 24 hours before it happens)

I'm using python 2.7 and the error occurs on a windows server.

Myrtue
  • 306
  • 2
  • 14

1 Answers1

0

I have the same issue, depending on what I put as a value in the "end" attribute of the print method, I got a threadLock:

from queue import LifoQueue
import threading
q = LifoQueue()

for i in range(100):
    q.put(i)

def process_job(q, threadName):
    while not q.empty():
        print(q.get(), end=' ')

workers = [
    threading.Thread(target=process_job, args=(q,'1')),
    threading.Thread(target=process_job, args=(q,'2')),
    threading.Thread(target=process_job, args=(q,'3')),
]

for w in workers:
    w.setDaemon(True)
    w.start()

The funniest part is that it works perfectly (as far as the end's value is blank " ").

Bevilaqua
  • 730
  • 1
  • 6
  • 13
  • 1
    Well, right after posting this, I found a comment from Mr. Alex Gaynor in the following page: [how-do-i-get-a-thread-safe-print-in-python-2-6](http://stackoverflow.com/questions/3029816/how-do-i-get-a-thread-safe-print-in-python-2-6) Overall, his answer seems very plausible for the issue. – Bevilaqua Jan 25 '17 at 11:13