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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:51:10+00:00 2026-06-10T08:51:10+00:00

I have python script run.py : def do(i): # doing something with i, that

  • 0

I have python script run.py:

def do(i):
    # doing something with i, that takes time

start_i = sys.argv[1]
end_i = sys.argv[2]
for i in range(start_i, end_i):
    do(i)

Then I run this script:

python run.py 0 1000000

After 30 minutes script is completed.
But, it’s too long for me.

So, I create bash script run.sh:

python run.py 0 200000 &
python run.py 200000 400000 &
python run.py 400000 600000 &
python run.py 600000 800000 &
python run.py 800000 1000000

Then I run this script:

bash run.sh

After 6 minutes script is completed.
Rather good. I’m happy.

But I think, there is another way to solve the problem (without creating bash script), isn’t there?

  • 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-10T08:51:11+00:00Added an answer on June 10, 2026 at 8:51 am

    You’re looking for the multiprocessing package, and especially the Pool class:

    from multiprocessing import Pool
    p = Pool(5)  # like in your example, running five separate processes
    p.map(do, range(start_i, end_i))
    

    Besides consolidating this into a single command, this has other advantages over your approach of calling python run.py 0 200000 & etc. If some processes take longer than others (and therefore, python run.py 0 200000 might finish before the others), this will make sure all 5 threads keep working until all of them are done.

    Note that depending on your computer’s architecture, running too many processes at the same time might slow them all down (for starters, it depends on how many cores your processor has, as well as what else you are running at the same time).

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

Sidebar

Related Questions

I have the code below in my Python script: def cmd_wui(argv, path_to_tx): Run a
I have a python script that I want always to run in the background.
I have a python script on a vps that I run a simple command
I have a Iron Python script that I want to run and then have
I have a python script that I run with 'exec'. When a function is
I have a Python script that takes in '.html' files removes stop words and
I have a very basic python script that does HTTP connection. import socket def
I have python script which downloads N number of images from website. I run
I have a new problem with a python script. When I try to run
I have a web service to which users upload python scripts that are run

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.