2

For some reason I keep failing to create a simple thread using python 3, the code below prints "test" once and then leaves the program running without printing anymore lines.

import time, threading

def test():
    print("test")
    threading.Timer(1, test).start()

test()

This code seems to work for millions of others, but not for me.

I'm not sure if this is just a printing failure or if the thread is not running at all. I've found and tried dozens of examples like the one above but they all give me the same issue (also time.sleep() has the same issue). I figure I might have to cancel the threading before I start a new one, but this has proven to be kind of difficult during a loop and I am not even sure that will work.

inControl
  • 2,215
  • 4
  • 24
  • 39
  • Did you try uninstall and install python again? wich version? I tryed in python 3.6.1 in windows and worked just fine. Wich OP? – developer_hatch Jun 06 '17 at 18:19
  • I tried this code on 2 seperate computers both with version 3.6.1 installed and it only prints test once, does this print multiple lines for you? – inControl Jun 06 '17 at 18:49
  • Yes indeed, it does... Black magic? I don't think so... must be a computable explanaination – developer_hatch Jun 06 '17 at 18:53

1 Answers1

0

I found the solution to my problem, I was using git bash and apperently it doesn't show values when printing them in a loop so it would only print the first time the function was called. It works fine using windows CMD.

inControl
  • 2,215
  • 4
  • 24
  • 39