In this line:
t = threading.Thread(target= ping(), args = pingArgs)
You are executing ping()
with no args and returning the result to target
. This is not threaded behavior. You need to change this to:
t = threading.Thread(target=ping, args=(pingArgs,))
You will also need to modify your definition of ping()
to accept arguments:
def ping(pingArgs):
There are a couple of other issues in your code, such as the print
statements in ping
(since the threads are asynchronous and printing to stdout is "non-atomic", your code will not reliably print
your print statements in order.). Once you get your code working, I would recommend putting it on codereview
for some further feedback.