Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7674927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:50:45+00:00 2026-05-31T16:50:45+00:00

The typical Python threadpool will have a structure like this one: def run(self): while

  • 0

The typical Python threadpool will have a structure like this one:

def run(self):
    while True:
        z=self.some_task_queue.get() 
        do_work(z)

So it appears that there is a continuous monitoring of the task queue.
How CPU intensive is this continuous monitoring of the task queue?

Would it be better to introduce some
sleep(few milliseconds) time to lower the CPU load?
In this way one could stop the monitoring of the task queue for some time when
all threads are busy and decrease the CPU load.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:50:46+00:00Added an answer on May 31, 2026 at 4:50 pm

    There is 0.0% cpu load while 1000 threads are blocked on .get() on my machine:

    #!/usr/bin/env python
    from __future__ import print_function
    import os
    import time
    from threading import Thread
    from Queue import Queue
    
    try: import psutil # pip install psutil
    except ImportError:
        psutil = None
    
    def f(queue):
        while True:
            item = queue.get() # block until an item is available
            print("got %s" % (item,))
            break # end thread
    
    # create threads
    q = Queue()
    threads = [Thread(target=f, args=(q,)) for _ in xrange(1000)]
    
    # starts them
    for t in threads:
        t.daemon = True # die with the program
        t.start()
    
    
    # show cpu load while the threads are blocked on `queue.get()`
    if psutil is None:
        print('Observe cpu load yourself (or install psutil and rerun the script)')
        time.sleep(10) # observe cpu load
    else:
        p = psutil.Process(os.getpid())
        for _ in xrange(10):
            print("cpu %s%%" % (p.get_cpu_percent(interval=0),))
            time.sleep(1)
    
    
    # finish threads
    for i in range(len(threads)):
        q.put_nowait(i) #note: queue is unlimited so there is no reason to wait
    
    for t in threads: t.join() # wait for completion
    print('done')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following typical python project file structure packageA +----subpackage1 +----classa.py +----subpackage2 +----classb.py
Suppose that I have the following python base class: class BaseClass(object): def a(): This
I'd like to create a regular expression in Python that will match against a
A typical producer-consumer problem is solved in python like below: from queue import Queue
I have two questions about creating thread safe types in python, and one related
What is the typical underlying data structure used to implement Python's built-in list data
I'm learning socket programming (in python) and I was wondering what the best/typical way
Typical way of creating a CSV string (pseudocode): Create a CSV container object (like
Typical jQuery over-use: $('button').click(function() { alert('Button clicked: ' + $(this).attr('id')); }); Which can be
The typical ConfigParser generated file looks like: [Section] bar=foo [Section 2] bar2= baz Now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.