Python 3 avoid starvation in Priority Queues - 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 avoid starvation in Priority Queues

In the post Python 3 priority queues – source code examples I spoke about the priority queues provided by Python 3. They are very useful, especially because they are provided out of the box. However, some features that are indispensable when doing multithreaded programming are missing. The most important is a way to avoid starvation. Starvation in the Python 3 PriorityQueue is due to the simple scheduling algorithm used. An item, with low priority, pushed into the queue can wait forever to be consumed if other items with higher priorities are pushed into the queue continuously. It is very simple to simulate this behaviour, take a look at the following code:"""simple module showing priority queue usage. Full info and description on www.xappsoftware.com """ import time import threading from random import randint # python 2.x import Queue import queue def producer(the_queue, timing): """[Produces and inserts new data into the_queue] Arguments: the_queue {[CQueue]} -- [the queue used to store data] timing {[Integer]} -- [the interval of time between the production of two items] """ while True: the_queue.


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,priority,queue,starvation

No comments:

Post a Comment