Async Techniques and Examples in Python Transcripts
Chapter: Course conclusion and review
Lecture: Review: Threads

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In contrast to the cooperative nature of asyncio type of concurrency on a single thread thread based parallelism lets the operating system
0:10 decide when our code gets to run. We have a single process and that process has a main thread which may kick off additional threads
0:16 spawn a couple additional pieces of work and then wait for them to complete and keep on running.
0:21 And the important thing is it's up to the OS to figure out when a thread runs, not up to our particular process.
0:28 Although the GIL does have something to say about it doesn't it, so here's the mental picture for threads.
0:33 Here's the programming model, so we're going to start with the built in threading library. There's no external things to install here.
0:40 We're going to have some function we want to run asynchronously but this is just normal Python code.
0:45 It doesn't do any sort of async await or stuff like that, it's just code and instead of running on the main thread, we're going to run somewhere else.
0:52 So given this, we'd like to create a bit of work that's going to run it so we set up the targets the arguments and if we want it not keep the
1:00 process alive or be canceled more easily we can say it's a daemon thread. And then we just start it, potentially do some
1:08 other work while it's running, or start other threads, things like that and then we're going to just wait for it to complete so we say work.join.
1:14 Of course we can give it a timeout. We were just saying wait forever until it finishes.


Talk Python's Mastodon Michael Kennedy's Mastodon