Why talk about threading?
A sequence of program instructions managed by OS
Processes
Threads
OS schedules what processes/threads run
Preemption!
Python 2
Python 3
The class way
import threading
import time
class sleeping_thread(threading.Thread):
def run(self):
time.sleep(1)
t = sleeping_thread()
t.start()
t.join()
The function way
import threading
import time
t = threading.Thread(
target=lambda: time.sleep(1)
)
t.start()
t.join()
Concurrency Primitives
Thread-safe Objects
What is a thread in Python?
Limitations in Python