Python Intermediate Tutorial #5 - Events and Daemon Threads

preview_player
Показать описание
In today's episode, we are talking about events and daemon threads!

Subscribe and Like for more free content!
Рекомендации по теме
Комментарии
Автор

What an amazing chanel!!! Please keep longer that tutorial series!

ates
Автор

Hey mate, I just wanted to thank you. The way you deliver your content is simply stellar, I have learned so much from your different series even as someone with experience in Python. You deserve way, way more subscribers!

charlie-cbbl
Автор

import threading

event = threading.Event()

def func():
print("Waiting to trigger event.")
event.wait() # stuck in terminal
print("Event triggered.")

t1 =
t1.start()

x = input("Trigger: (y/n) ").lower()
if x == "y":
event.set() # activate event

kvelez
Автор

If you are using VS Code (because we have to be extra bout everything)

import os

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)

As long as a file is in the same directory as the python program you are trying to run, you won't need to include the file path. There is like 800 answers to this problem, and this is the cleanest one I could find.

Idk how this will work for Mac or Linux, but I imagine you are not using VS code outside a windows machine unless you like masochism.

Dr.Cosmar
Автор

btw, the most exciting mini-project up to this point

quickexpp
Автор

You should have more subscribers, you deliver your content well.

molenz
Автор

I have a question, when we create a thread is it like some how connected to the main thread or is it independent of it and works completely on it's own?
By the way this is one of the most informative channels on YT .

rajat_d.
Автор

How do you stop the threads in the program? (Instead of just typing CTRL-C)?

eugenmalatov
Автор

this stuff is awesome I like working with files from inside id kind of like linux stuff!

Radical
Автор

last example wasn't clear didn't get what daemon threads used for.
you can still achieve the same result without daemon threading and even without threading at all

khaled-dev
Автор

Is the While True loop actually needed? wont the thread be constantlly running the readFile() Function?
Hope you read it!

quickexpp
Автор

3 yr gone still best, god bless you. Make a flet app with threading to plot websocket feed ccandle chart .... you can make playlist series on it..

pyalgoGPT
Автор

Thanks a lot i have learned a lot from this channel, By the way i have one question here in second function how that "text" global variable got accessed ?

siddeshwarvanga
Автор

thnx so much for your videos! Do you have a video on with statements cuz thats a new one for me...?

eliyaben
Автор

So when t1 is waiting because event is waiting so both the threads are waiting or t1 is still running

pokeera
Автор

Can anyone please explain the difference between target=myfunction vs target=myfunction () ?

pythonicd
Автор

So that event function applies to all threads then? Not just t1? Am I reading the code and understanding it correctly? Wait I get it you can make multiple event instances if you want different events for different threads.

asdf
Автор

What is the correct pronounciation of daemon? Not like demon?

eugenmalatov
Автор

Hi how to run the async method in thread without using Asyncio because it is causing furture issue in asyuomotoclient while inserting record in db. Thanks in advance

rameshb
Автор

Love the channel. Thanks! My question is: Once the script terminates the daemon thread is still running? Is there any way other than through a task manager to stop the thread? Seems to me there us a lot of potential here for memory leak scenarios. What are best practices regarding daemon termination?

thomasgoodwin