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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:16:31+00:00 2026-05-23T11:16:31+00:00

I have a folder with 500 input files (total size of all files is

  • 0

I have a folder with 500 input files (total size of all files is ~ 500[MB]).

I’d like to write a python script that does the following:

(1) load all of the input files to memory

(2) initializes an empty python list that will later be used … see bullet (4)

(3) start 15 different (independent) processes: each of these uses the same input data [from (1)] — yet uses a different algorithms to processes it, thus generating different results

(4) I’d like all the independent processes [from step (3)] to store their output in the same python list [same list that was initialized in step (2)]

Once all 15 processes have completed their run, I will have one python list that includes the results of all the 15 independent processes.

My question is, is it possible to do the above efficiently in python? if so, can you provide a scheme / sample code that illustrates how to do so?

Note #1: I will be running this on a strong, multi-core server; so the goal here is to use all the processing power while sharing some memory {input data, output list} among all the independent processes.

Note #2: I am working in a Linux environment

  • 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-23T11:16:32+00:00Added an answer on May 23, 2026 at 11:16 am

    ok I just whipped this up using zeromq to demonstrate a single subscriber to multiple publishers. You could probably do the same with queues but you would need to manage them a bit more. zeromq sockets just work which makes it nice for things like this IMO.

    """
    demo of multiple processes doing processing and publishing the results
    to a common subscriber
    """
    from multiprocessing import Process
    
    
    class Worker(Process):
        def __init__(self, filename, bind):
            self._filename = filename
            self._bind = bind
            super(Worker, self).__init__()
    
        def run(self):
            import zmq
            import time
            ctx = zmq.Context()
            result_publisher = ctx.socket(zmq.PUB)
            result_publisher.bind(self._bind)
            time.sleep(1)
            with open(self._filename) as my_input:
                for l in my_input.readlines():
                    result_publisher.send(l)
    
    if __name__ == '__main__':
        import sys
        import os
        import zmq
    
        #assume every argument but the first is a file to be processed
        files = sys.argv[1:]
    
        # create a worker for each file to be processed if it exists pass
        # in a bind argument instructing the socket to communicate via ipc
        workers = [Worker(f, "ipc://%s_%s" % (f, i)) for i, f \
                   in enumerate((x for x in files if os.path.exists(x)))]
    
        # create subscriber socket
        ctx = zmq.Context()
    
        result_subscriber = ctx.socket(zmq.SUB)
        result_subscriber.setsockopt(zmq.SUBSCRIBE, "")
    
        # wire up subscriber to whatever the worker is bound to 
        for w in workers:
            print w._bind
            result_subscriber.connect(w._bind)
    
        # start workers
        for w in workers:
            print "starting workers..."
            w.start()
    
        result = []
    
        # read from the subscriber and add it to the result list as long
        # as at least one worker is alive
        while [w for w in workers if w.is_alive()]:
            result.append(result_subscriber.recv())
        else:
            # output the result
            print result
    

    oh and to get zmq just

    $ pip install pyzmq-static
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get a simple test perl script working. Have the following files/folder structure
I have a php script that steps through a folder containing tab delimited files,
I have a script that creates a folder called videos on a USB drive,
I have just added all the Drupal files to a folder named /_dp70/ but
I have a bunch of files that get updated in the folder C:\Email. These
I have a table that contains file paths, like so: -------------------- |Files | --------------------
I have php code for list all .swf files in a folder. (The name
I have a ssis package that does the following copies a file from an
I have folder structure and I would like to create JSON objects based on
I have folder on which i want to apply security like the current user

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.