thread.start_new_thread(target=self.socketFunctionRead1())
print "Thread 1"
thread.start_new_thread(target=self.socketFunctionWrite1())
print "Thread 2"
thread.start_new_thread(target=self.socketFunctionRead2())
print "Thread 3"
thread.start_new_thread(target=self.socketFunctionWrite2())
print "Thread 4"
I am trying to start multiple threads, but only one thread is started, how can I make the program go further by starting the other threads?
Instead of
thread.start_new_thread(target=self.socketFunctionRead1()),try
thread.start_new_thread(target=self.socketFunctionRead1)Because of the parenthese, the function is called and the return value of the function is assigned to target. Since
thread.start_new_thread(target=self.socketFunctionRead1())is probably a blocking call, only this function gets called.In thread.start_new_thread, target should be a callable (An object that behaves like a function).
Edit:
From the Python documentation:
This means that you should call thread.start_new_thread(self.socketFunctionRead1).
If you pass keyword arguments to start_new_thread, they will get passed to self.socketFunctionRead1.
The target for your thread is required and not a keyword argument.