Reputation: 11
The Code:
#!/usr/bin/env python
# coding: utf-8
from threading import Thread
from time import *
print strftime("%Y.%m.%d - %H:%M:%S;\n", localtime())
def pruefeStatusAlarmUndBetrieb():
sleep(3)
print "Alarm und Betrieb"
print strftime("%Y.%m.%d - %H:%M:%S;\n", localtime())
def pruefeStatusEingaenge():
sleep(4)
print "Eingänge"
print strftime("%Y.%m.%d - %H:%M:%S;\n", localtime())
def pruefeStatusAusgaenge():
sleep(6)
print "Ausgänge"
print strftime("%Y.%m.%d - %H:%M:%S;\n", localtime())
def pruefe():
s = Thread(target=pruefeStatusAlarmUndBetrieb())
s.start()
t = Thread(target=pruefeStatusEingaenge())
t.start()
u = Thread(target=pruefeStatusAusgaenge())
u.start()
pruefe()
what Python does:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/????/Documents/smartsys/test/test_threading.py
2016.12.09 - 19:27:23;
Alarm und Betrieb
2016.12.09 - 19:27:26;
Eingänge
2016.12.09 - 19:27:30;
Ausgänge
2016.12.09 - 19:27:36;
Process finished with exit code 0
Sorry for all that german terms in it, hopefully it doesn't hinder anyone to understand that piece of code.
What i'm trying to solve:
I expect that code to run parallel, but its runing von after another thread, so its a serial operation, if a add an infinite loop with sleepcommand, execution will stay inside infinite loop, so the other threads will be still ignored.
What am i doing wrong, or have i missunderstood?
At the end all 3 threads should run parallel and do what ever i will supose them to do, after having slept a short period of thime.
Upvotes: 0
Views: 38
Reputation: 2220
You must no call the target in s = Thread(target=pruefeStatusAlarmUndBetrieb)
. Remove ().
Upvotes: 3