After reading: http://pymotw.com/2/threading/#daemon-vs-non-daemon-threads I expect the following code to complete in 2 seconds:
from threading import Thread from time import sleep def a(): i = 0 while 1: print i i+=1 t = Thread(target=a) t.setDaemon(True) t.run() sleep(2)
However, he continues to print numbers forever. Am I missing something? I am on win7. I get the same behavior from windows shell and inaction.
You should call t.start() , not t.run() . The first will spawn a new thread and call run itself from there. Calling the launch of your choice causes you to execute function a in the current thread.
t.start()
t.run()
run
a
Source: https://habr.com/ru/post/1496113/More articles:entering text into a text box - javascriptAutomatically checking JavaDoc with Maven - javaHow to exchange code for token for importing gmail address book - c #Using the $ literal in the GNUMakefile path - makefileflask AttributeError: HTMLString object does not have attribute '__call__' - pythonHow does GA track page load time on _trackPageView? - google-analyticsAndroid: Can I programmatically read deleted contacts? - androidHow to round System.Decimal in .Net to a series of significant digits - decimalunrecognized configuration parameter "custom_variable_classes" - postgresqlExclude .csproj from VisualStudio 2012.sln when using Mono Compiler - monoAll Articles