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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:30:16+00:00 2026-06-14T02:30:16+00:00

I am creating a small python script to create n number of threads and

  • 0

I am creating a small python script to create n number of threads and each thread invoking curl m times on my web app.

The script is invoked
./multithreadedCurl.py 10 100

I expect the curl to b executed 10*100 = 1000 times.
However I see that it is creating n threads but each thread is only invoking curl only once.
Is this due to the fact that am using subprocess?

Python version Python 2.7.2
OS: Mac OSX 10.8.2 (Mountain Lion)

Any help much appreciated and I am very new to python and this is my second day of python development.


#!/usr/bin/python

import threading
import time
import subprocess
import sys
import math

# Define a function for the thread
def run_command():
        count  = 0
        while (count < int(sys.argv[2])):
                subprocess.call(["curl", "http://127.0.0.1:8080"])
                count += 1

threadCount = 0
print sys.argv[0]
threadLimit = int(sys.argv[1])
while threadCount < threadLimit:
        t=threading.Thread(target=run_command)
        t.daemon = True  # set thread to daemon ('ok' won't be printed in this case)
        t.start()
        threadCount += 1`
  • 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-14T02:30:17+00:00Added an answer on June 14, 2026 at 2:30 am

    By setting t.daemon = True you say that

    http://docs.python.org/2/library/threading.html
    A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program exits when only daemon threads are left. The initial value is inherited from the creating thread. The flag can be set through the daemon property.

    So you should either use t.daemon = False or wait for all the threads to complete with join.

    threads = []
    while len(threads) < threadLimit:
        t=threading.Thread(target=run_command)
        threads.append(t)
        t.daemon = True
        t.start()
    [thread.join() for thread in threads]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a small Python script to manage different classes of servers (FTP, HTTP,
I'm creating a small app using python 2.7 with google app engine and I'm
I'm creating a small framework for my web projects in PHP so I don't
So I'm making a small App Engine application through python which reads a timetable
Suppose I need to create my own small DSL that would use Python to
I've written a small script in Python that pings all subnets of my school's
I want to hack around with the Python interpreter and try creating a small
I am in the process of writing a small(er) Python script to automate a
I have a task to create a website that'll allow creating small websites, mostely
I am writing a small python script like this: #!/usr/bin/env python from sqlite3 import

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.