Skip to content Skip to sidebar Skip to footer

Python Threads Not Running In Parallel

Currently I am trying to have two threads running in parallel, but what seems to be happening is the first thread to be started is the only one that runs. My code is listed below,

Solution 1:

threading.Thread(getTouchData(fac))

This is not the proper way to call a Thread. Thread needs to receive a callable to the target kwarg, and you need to pass args in a tuple to the args kwarg. Altogether:

threading.Thread(target=getTouchData, args=(fac,))

Per the docs:

class threading.Thread(group=None, target=None, name=None, args=(), kwargs={})

This constructor should always be called with keyword arguments. Arguments are:

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

args is the argument tuple for the target invocation. Defaults to ().

Post a Comment for "Python Threads Not Running In Parallel"