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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:22:02+00:00 2026-05-30T20:22:02+00:00

I am using Python as a script language to do some data processing and

  • 0

I am using Python as a script language to do some data processing and call command-line tools for number crunching. I wish to run command-line tools in parallel since they are independent with each other. When one command-line tool is finished, I can collect its results from the output file. So I also need some synchronization mechanism to notify my main Python program that one task is finished so that the result could be parsed into my main program.

Currently, I use os.system(), which works fine for one-thread, but cannot be parallelized.

Thanks!

  • 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-30T20:22:03+00:00Added an answer on May 30, 2026 at 8:22 pm

    Use the Pool object from the multiprocessing module. You can then use e.g. Pool.map() to do parallel processing. An example would be my markphotos script (see below), where a function is called multiple times in parallel to each process a picture.

    #! /usr/bin/env python
    # -*- coding: utf-8 -*-
    # Adds my copyright notice to photos.
    #
    # Author: R.F. Smith <rsmith@xs4all.nl>
    # $Date: 2012-10-28 17:00:24 +0100 $
    #
    # To the extent possible under law, Roland Smith has waived all copyright and
    # related or neighboring rights to markphotos.py. This work is published from
    # the Netherlands. See http://creativecommons.org/publicdomain/zero/1.0/
    
    import sys
    import subprocess
    from multiprocessing import Pool, Lock
    from os import utime, devnull
    import os.path
    from time import mktime
    
    globallock = Lock() 
    
    def processfile(name):
        """Adds copyright notice to the file.
    
        Arguments:
        name -- file to modify
        """
        args = ['exiftool', '-CreateDate', name]
        createdate = subprocess.check_output(args)
        fields = createdate.split(":") #pylint: disable=E1103
        year = int(fields[1])
        cr = "R.F. Smith <rsmith@xs4all.nl> http://rsmith.home.xs4all.nl/"
        cmt = "Copyright © {} {}".format(year, cr)
        args = ['exiftool', '-Copyright="Copyright (C) {} {}"'.format(year, cr),
                '-Comment="{}"'.format(cmt), '-overwrite_original', '-q', name]
        rv = subprocess.call(args)
        modtime = int(mktime((year, int(fields[2]), int(fields[3][:2]),
                              int(fields[3][3:]), int(fields[4]), int(fields[5]),
                              0,0,-1)))
        utime(name, (modtime, modtime))
        globallock.acquire()
        if rv == 0:
            print "File '{}' processed.".format(name)
        else:
            print "Error when processing file '{}'".format(name)
        globallock.release()
    
    def checkfor(args):
        """Make sure that a program necessary for using this script is
        available.
    
        Arguments:
        args -- list of commands to pass to subprocess.call.
        """
        if isinstance(args, str):
            args = args.split()
        try:
            with open(devnull, 'w') as f:
                subprocess.call(args, stderr=subprocess.STDOUT, stdout=f)
        except:
            print "Required program '{}' not found! exiting.".format(args[0])
            sys.exit(1)
    
    def main(argv):
        """Main program.
    
        Arguments:
        argv -- command line arguments
        """
        if len(argv) == 1:
            binary = os.path.basename(argv[0])
            print "Usage: {} [file ...]".format(binary)
            sys.exit(0)
        checkfor(['exiftool',  '-ver'])
        p = Pool()
        p.map(processfile, argv[1:])
        p.close()
    
    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 have a Python script I recently wrote that I call using the command
I'm trying to host a python script using an apache web server, but the
I have a batch file containing a python script using the Output template> %(NAME)s
I'm already recording from my iSight from a python script using the pyobjc bridge
I'm using Python with pywin32's adodbapi to write a script to create a SQL
I've created a small python script to toggle between two files I'm using for
Suppose I have a python script called my_parallel_script.py that involves using multiprocessing to parallelize
I'm trying to compile my python script into a single .exe using gui2exe (which
I'm currently using the toprettyxml() function of the xml.dom module in a Python script
I'm trying to submit a few forms through a Python script, I'm using the

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.