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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:46:12+00:00 2026-06-17T05:46:12+00:00

I have a multiprocess program that fetches web pages that all have different response

  • 0

I have a multiprocess program that fetches web pages that all have different response time. The results are stored in the process queue according to the FIFO rule. I would like to indentify the results from the queue by the process number. This is my test rig and what I have achieved so far using two queues. Any other way? I have tried to use a global list to store the results but the two processes doesn’t seem to share the same memory space.

#!/usr/bin/python3.2

import time
from multiprocessing import Process, Queue

def myWait(processNb, wait, resultQueues):
    startedAt = time.strftime("%H:%M:%S", time.localtime())
    time.sleep(wait)
    endedAt = time.strftime("%H:%M:%S", time.localtime())
    resultQueues[processNb].put('Process %s started at %s wait %s ended at %s' % (processNb, startedAt, wait, endedAt))

# queue initialisation
resultQueues = [Queue(), Queue()]

# process creation arg: (process number, sleep time, queue)
proc =  [
    Process(target=myWait, args=(0, 2, resultQueues,)),
    Process(target=myWait, args=(1, 1, resultQueues,))
    ]

# starting processes
for p in proc:
    p.start()

for p in proc:
    p.join()

# print results
print(resultQueues[0].get())
print(resultQueues[1].get())
  • 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-17T05:46:13+00:00Added an answer on June 17, 2026 at 5:46 am
    • mp.Processs can be given a name parameter, which the target
      function myWait can then access with mp.current_process().name.
      So it is not necessary to pass processNb.
    • Keep interprocess communication to a minimum. Instead of passing a
      formatted string through the queue, just pass the parts of the string
      that will change in a tuple: (name, wait, startedAt, endedAt).

    So, you could do it with one queue like this:

    import time
    import multiprocessing as mp
    
    def myWait(wait, resultQueue):
        startedAt = time.strftime("%H:%M:%S", time.localtime())
        time.sleep(wait)
        endedAt = time.strftime("%H:%M:%S", time.localtime())
        name = mp.current_process().name
        resultQueue.put(
            (name, wait, startedAt, endedAt))
    
    
    # queue initialisation
    resultQueue = mp.Queue()
    
    # process creation arg: (process number, sleep time, queue)
    proc =  [
        mp.Process(target=myWait, name = '0', args=(2, resultQueue,)),
        mp.Process(target=myWait, name = '1', args=(1, resultQueue,))
        ]
    
    # starting processes
    for p in proc:
        p.start()
    
    for p in proc:
        p.join()
    
    # print results
    for p in proc:
        name, wait, startedAt, endedAt = resultQueue.get()
        print('Process %s started at %s wait %s ended at %s' %
              (name, startedAt, wait, endedAt))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a multiprocess system that needs to process a bunch of directories,
I have a multi-process python application (processes are spawned by uwsgi) that needs to
Not sure what parallel programing means... but I have two thoughts of that Process
I have one simple program of wsgi. from wsgiref.simple_server import make_server import time def
have written this little class, which generates a UUID every time an object of
I have a number of scripts written in Python 2.6 that can be run
I have an Activity that is defined to be singleTop so that only the
I'm studying Erlang's process model at the moment. I have hit a snag in
I'm running into problem about redirect stdout of multi process. Assuming I have process
I'm building a multiprocess architecture that seems to be a strange meld of a

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.