In Python, How Do You Call an Unbound Function as a New Thread with the thread Module?

Problem scenario
You want to write a program to call a unbound function in a new thread with the threading module. How do you do this?

Solution
Run this program (e.g., python foobar.py):

import _thread as thread
def contint():
  print("Hello!")

#if name == "main":
foobar = thread.start_new_thread(contint, () )
print("thread finished exiting")

Leave a comment

Your email address will not be published. Required fields are marked *