Ich spiele nur mit Multi-Threading, aber ich kann es nicht funktionieren. Ich habe mir andere Fragen angeschaut, aber keine hilft mir wirklich. Hier ist mein Code so weit:Wie funktioniert Multi-Threading in Python 3.4?
import threading, time
def hello():
for i in range(1,5):
time.sleep(1)
print("Hello")
def world():
for i in range(1,5):
time.sleep(1)
print("World")
newthread = threading.Thread(hello())
newthread.daemon = True
newthread.start()
otherthread = threading.Thread(world())
otherthread.daemon = True
otherthread.start()
print("end")
erwarte ich etwas zu bekommen wie:
Hello
World
Hello
World
Hello
World
Hello
World
end
Aber stattdessen erhalte ich:
Hello
Hello
Hello
Hello
World
World
World
World
end
Danke für die Antwort, funktionierte perfekt, und ich fügte eine kleine Verzögerung zwischen den Fäden beginnen die Ausgabe richtig zu machen. :) –