Python daemon threads 😈

preview_player
Показать описание
python daemon threads tutorial example explained

#python #daemon #threads

# ************************************************************
# Python daemon threads
# ************************************************************

# daemon thread = a thread that runs in the background, not important for program to run
# your program will not wait for daemon threads to complete before exiting
# non-daemon threads cannot normally be killed, stay alive until task is complete
#
# ex. background tasks, garbage collection, waiting for input, long running processes

import threading
import time

def timer():
print()
count = 0
while True:
count += 1
print("logged in for: ", count, "seconds")

x = threading.Thread(target=timer, daemon=True)

answer = input("Do you wish to exit?")

# ************************************************************

Bro Code merch store 👟 :
===========================================================
===========================================================
Рекомендации по теме
Комментарии
Автор

#
# Python daemon threads
#

# daemon thread = a thread that runs in the background, not important for program to run
# your program will not wait for daemon threads to complete before exiting
# non-daemon threads cannot normally be killed, stay alive until task is complete
#
# ex. background tasks, garbage collection, waiting for input, long running processes

import threading
import time


def timer():
print()
count = 0
while True:
time.sleep(1)
count += 1
print("logged in for: ", count, "seconds")


x = threading.Thread(target=timer, daemon=True)
x.start()

# x.setDaemon(True)
# print(x.isDaemon())

answer = input("Do you wish to exit?")

#

BroCodez
Автор

"when all the daemons are killed" is a combination of words I did NOT expect to hear in a python tutorial. Thanks anyway Bro! You're awesome!

brunocardoso
Автор

anyone know why "logged in for seconds" will display on the same line as "Do you wish to exit"? i even copy and pasted the exact code and it still does it. no big deal just curious on how to display it the same way as in the video

edit: i was able to fix it by adding \n to answer = input("Do you wish to exit?")

NoPont
Автор

Great content, that's what I was looking for, a perfect solution for a problem

kn
Автор

Very clear explanation on demon. Thanks so much 😃

kotai
Автор

great video, all other video I watched made this seem so complex

dx
Автор

it's not working for me
i get the do you wish to exit and timer isn't counting
then after I type in "ok" it starts counting from 1 second and doesn't stop

oximas-oevf
Автор

So if the demons get mad, does the computer stops working?

mauricesalaman
Автор

fellow based doom enjoyer
thanks for the lesson bro

ilordepic
Автор

Yo Bro! Is python enough in beginning to get a job in IT industry? What you think?

provokator-provocateur
Автор

Could you explain how answer = input("Do you wish to exit?") is tied into the timer function. I can't get it to stop counting and I see no reason why it should - Thanks!!

edmerzlak
Автор

bro, when I ran your code, I had to input at the bottom of the terminal, not right next to "Do you wish to exit?", why is that ?

AniGuy-smiy
Автор

Why do we need time.sleep() before the count increment?

inderjitsaini
Автор

repent and come to Jesus Christ. Be not partakers in the unfruitful works of darkness.

peterhansen