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

  • Home
  • SEARCH
  • 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 8394299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:01:25+00:00 2026-06-09T20:01:25+00:00

Im trying to run a single external program with multiple arguments in python. For

  • 0

Im trying to run a single external program with multiple arguments in python. For that I use something like

for i in range(10):
    subprocess.Popen(["./foo", i])

The processes are completly independent. Nevertheless, they run only on a single core on my Mac OS X. Is there a simple way to distribute the processes over all cores (4 in my case)?

  • 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-09T20:01:26+00:00Added an answer on June 9, 2026 at 8:01 pm

    Below is an example of a program that uses multiprocessing to convert several pictures in parallel;

    """Convert DICOM files to PNG format, remove blank areas. The blank erea
       removal is based on the image size of a Philips flat detector. The image
       goes from 2048x2048 pixels to 1574x2048 pixels."""
    
    import os
    import sys
    import subprocess
    from multiprocessing import Pool, Lock
    
    globallock = Lock()
    
    def checkfor(args):
        """Make sure that a program necessary for using this script is
        available."""
        if isinstance(args, str):
            args = args.split()
        try:
            f = open('/dev/null')
            subprocess.call(args, stderr=subprocess.STDOUT, stdout=f)
            f.close()
        except:
            print "Required program '{}' not found! exiting.".format(args[0])
            sys.exit(1)
    
    def processfile(fname):
        """Use the convert(1) program from the ImageMagick suite to convert the
           image and crop it."""
        size = '1574x2048'
        args = ['convert', fname, '-units', 'PixelsPerInch', '-density', '300',
                '-crop', size+'+232+0', '-page', size+'+0+0', fname+'.png']
        rv = subprocess.call(args)
        globallock.acquire()
        if rv != 0:
            print "Error '{}' when processing file '{}'.".format(rv, fname)
        else:
            print "File '{}' processed.".format(fname)
        globallock.release()
    
    def main(argv):
        """Main program.
    
        Keyword arguments:
        argv -- command line arguments
        """
        if len(argv) == 1:
            path, binary = os.path.split(argv[0])
            print "Usage: {} [file ...]".format(binary)
            sys.exit(0)
        checkfor('convert')
        p = Pool()
        p.map(processfile, argv[1:])
        p.close()
    
    
    ## This is the main program ##
    if __name__ == '__main__':
        main(sys.argv)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run multiple SQL queries in a single SQL server thread through
I'm trying to run some external executable code from within Python and then make
I am trying to run a program like this: $CMD $ARGS where $ARGS is
Background I'm trying to figure out how to run a single unittest against multiple
I have to use sudo to run my program: sudo ./my_program I am trying
I'm trying to run a single unit test in my Rails app, I'm using
I'm trying to update a single record in a table, but when I run
I am trying run a program from a qmake .pro file which modifies the
Trying to run my program in FreeBSD OS, I have the following results: $
I have a single .java (driver.java) file I'm trying to compile and run from

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.