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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:18:51+00:00 2026-05-27T15:18:51+00:00

I have a subprocess function (called parseContents) that gets called using the following code:

  • 0

I have a subprocess function (called parseContents) that gets called using the following code:

def main():
   p = Process(target=parseContents, args=(event.name,))
   p.start()
   p.join()

Utilizing the multiprocessing module and the Queue method, how would I go about passing a variable from parseContents back to main to be used after the p.join() line?

I’ve read that I would use:

  from multiprocessing import Queue
  queue = Queue()
  queue.put( myVar ) #obviously this would be inside parseContents()
  print queue.get( myVar )  #obviously this would be inside main()

Do I need to pass the ‘queue’ variable/instance to my parseContents function after calling it in my main so the child process knows about the queue?

What would be a correct implementation of a multiprocessing queue between parent and child processes as constructed in the main(): segment above?

  • 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-27T15:18:51+00:00Added an answer on May 27, 2026 at 3:18 pm

    To use a Queue in this way you have to instantiate it in main() and pass it to parseContents as an argument. Once you do that you should be able to use the code you have (in the correct places) to pass the item from the child process to the parent process.

    The Python docs warn that you should not attempt to join the child process if the Queue is not empty, so make sure to get all of the items out of the queue before you call join. In fact, you should be able to run the code without calling join at all because queue.get will wait until there is an item in the Queue.

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

Sidebar

Related Questions

I have a python function that makes a subprocess call to a shell script
I have a ruby application that executes ant as a subprocess using backtick. This
I have the following python code: import pty import subprocess os=subprocess.os from subprocess import
I have the following python function that allows me to run shell commands from
I have some code that I've managed to narrow down to the following smallest-code
I have a testing script that needs to open a process (a Pyro server),
I'm working on a nifty little function: def startProcess(name, path): Starts a process in
I have a snippet of code which works: p = subprocess.Popen('psftp servername'.split(),stdin=subprocess.PIPE, tdout=subprocess.PIPE, shell=True)
Greetings. I have written a little python script that calls MySQL in a subprocess.
Say if I have four functions as below: def foo(): subprocess.Popen('start /B someprogramA.exe', shell=True)

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.