I'm learning threading in Python and tried to create a threading program as shown below
def main():
print('Hello world!')
if __name__ == "__main__"
thread1 = threading.Thread(target=main)
However when changing the target=main(), it executes but some parts of my code don't work then What am I doing wrong?
CodePudding user response:
You created a variable thread1
the thread which prepares the thread(clarification needed, am not sure exactly) to execute the function main()
. To execute it just run thread1.start()
and done!
CodePudding user response:
Just add thread1.start()
and your thread should execute! (If you need to pass arguments to the target function, add args=(your, arguments, here)
)