Python 3 – Threads and daemons - Online Free Computer Tutorials.

'Software Development, Games Development, Mobile Development, iOS Development, Android Development, Window Phone Development. Dot Net, Window Services,WCF Services, Web Services, MVC, MySQL, SQL Server and Oracle Tutorials, Articles and their Resources

Tuesday, August 7, 2018

Python 3 – Threads and daemons

In the post Python threading – an intro I introduced something about python threads, I explained the GIL (Global Interpreter Lock) and how to instantiate workers and timers. The GIL is the topic you must know to take full advantages from python threads. In this post I'm going to explain the following topics: Subclassing Thread Instantiating daemon thread Listing all instatiated threads Signaling threads – Subclassing Thread Since the module "threading" is implemented in an object oriented way, every thread corresponds to an object and you can easily subclass it. The simplest way to subclass is adding a parameter to the initialization and modify the run method to print the passed name:''' subclassing threads ''' import threading class SubThread(threading.Thread): ''' SubClass of Thread ''' def __init__(self, name): threading.Thread.__init__(self) self.name = name def run(self): print(self.name)in this way the subclassed thread will print the name passed as soon as the run method is called:if __name__ == '__main__': for i in range(5): t = SubThread('thread-'+str(i)) t.


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to

python,Tower of Babel,daemon,thread

No comments:

Post a Comment