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 8360047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:20:32+00:00 2026-06-09T11:20:32+00:00

This is my code and I am getting varied output. import threading import time

  • 0

This is my code and I am getting varied output.

import threading
import time

def th_fun(limit,sleeptime):
    print '%s' % (limit)
    print '%s number of threads are active' % (threading.activeCount())
    time.sleep(sleeptime)



if __name__ == '__main__':
    for i in range(5):
        t = threading.Thread(target = th_fun , args = (i,1))
        t.start()

Can someone tell when a thread becomes inactive? My understanding is that 5 different thread objects are created and run and as soon as time.sleeptime() is executed it becomes inactive.

  • 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-06-09T11:20:33+00:00Added an answer on June 9, 2026 at 11:20 am

    The output is varied because the order that multiple threads are executed in, and the speeds of each of them, is nondeterministic.

    As soon as t.start() occurs, the function gets called with the arguments you provided. However, this is running in the background while the next thread is set up and started. Depending on the amount of time it takes to run, it might finish running before the next thread starts, or it could finish after all the other threads have started.

    It might help your understanding to add the line:

        print "Finished thread %s" % limit
    

    at the end of your function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with getting this code to print out to file due
I am Getting a run time Exception while using this code Runtime rt =
I've spent a lot of time reading c tutorials and getting this code to
I am having a problem getting this code to work. Basically I Go from
This code compiled properly on Visual Studio 2010 on Windows, but I'm getting this
I am getting a StackOverflow Error in this code: EDIT [XmlAttribute(ID)] public string ID
I am getting segmentation fault in this code but i cant figure out why.
I have this code and I keep getting undefined if I test the selectedIndex.
I'm not really getting how this code does what it does: char shellcode[] =
I am getting a file not found exception for this code: (System.IO.FileNotFoundException : Die

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.