Skip to main content
minor formatting change to remove the need to scroll to read all of comment
Source Link
Ray Mairlot
  • 29.4k
  • 12
  • 105
  • 126

Or simpler


import threading

def to_run(): # should not take arguments.
    ... # code to execute in the thread (can be a loop, ...) 
        # it uses the same variables as in the main thread.

new_thread = threading.Thread() # create a new thread object.
new_thread.run = to_run
new_thread.start() # the new thread is created and then is running.

Or simpler


import threading

def to_run(): # should not take arguments.
    ... # code to execute in the thread (can be a loop, ...) it uses the same variables as in the main thread.

new_thread = threading.Thread() # create a new thread object.
new_thread.run = to_run
new_thread.start() # the new thread is created and then is running.

Or simpler


import threading

def to_run(): # should not take arguments.
    ... # code to execute in the thread (can be a loop, ...) 
        # it uses the same variables as in the main thread.

new_thread = threading.Thread() # create a new thread object.
new_thread.run = to_run
new_thread.start() # the new thread is created and then is running.
Source Link

Or simpler


import threading

def to_run(): # should not take arguments.
    ... # code to execute in the thread (can be a loop, ...) it uses the same variables as in the main thread.

new_thread = threading.Thread() # create a new thread object.
new_thread.run = to_run
new_thread.start() # the new thread is created and then is running.