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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:42:50+00:00 2026-06-04T01:42:50+00:00

Basically I have the following code: import multiprocessing import time class MyProcess(multiprocessing.Process): def __init__(self,

  • 0

Basically I have the following code:

import multiprocessing
import time

class MyProcess(multiprocessing.Process):

    def __init__(self, ):
        multiprocessing.Process.__init__(self)
        self.queue = multiprocessing.Queue()

    def run(self):
        print "Subprocess starting!"
        time.sleep(4)
        print "Subprocess exiting!"

    def addToQueue(self):
        starttime = time.time()
        count=0
        print "Adding stuff to queue..."
        while time.time()-starttime  < 4:
            self.queue.put("string")
            count += 1
        print "Added %d objects!" % count

        #self.queue.close()


if __name__ == "__main__":
    process = MyProcess()
    process.start()
    print "Waiting for a while"
    time.sleep(2)
    process.addToQueue()
    time.sleep(1)
    print "Child process state: %d" % process.is_alive()

When the main process finishes, it doesn’t quit. Nothing happens, it just blocks. The only I found to quit was by killing it (not SIGTERM, SIGKILL).

If I use that commented line, it quits but issuing an IOError.

I looked at the code for the multiprocessing.queue and it uses a os.pipe() spawned in another thread (threading.Thread). What I suspect is that the thread blocks when writing to the pipe, and when the close() method is used, it raises the IOError.

So my question is: is there a cleaner way to handle this?

I mean, I have this scenario where a queue is constantly being written on. When the receiving process quits (cleanly or not), I should just close the queue and get an IOError on the sender process?

Edit: The output of the process

Waiting for a while
Subprocess starting!
Adding stuff to queue...
Subprocess exiting!
Added 1822174 objects!
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/queues.py", line 266, in _feed
    send(obj)
IOError: [Errno 32] Broken pipe
Child process state: 0

This part only occurs when using the self.queue.close() that is commented:

Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/queues.py", line 266, in _feed
    send(obj)
IOError: [Errno 32] Broken pipe
  • 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-04T01:42:54+00:00Added an answer on June 4, 2026 at 1:42 am

    I’m answering my own question since not everybody reads comments. After the hint from user mata in the comments, I tested the sample code in the question adding a call to time.sleep(0.01) inside the loop that adds object to the queue, so I could limit the number of objects that would be added to the queue:

    def addToQueue(self):
            starttime = time.time()
            count=0
            print "Adding stuff to queue..."
            while time.time()-starttime  < 4:
                self.queue.put("string")
                count += 1
                time.sleep(0.01)
            print "Added %d objects!" % count
    

    So, when the number of objects is low (less then 3800 in this example), the process quits normally. But when there are lots of objects, there seems to be some locking in the pipe between the processes.

    But that raises another question for me: is this a bug? Should I report it? Or is this just normal expected behavior?

    Big thanks to user mata for pointing this possibility!

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

Sidebar

Related Questions

I'm struggling with the following code. Basically, I have a class Foo and nested
I'm having an issue with rails involving javascript. Basically, I have the following code:
I basically have the following class: .sf-sub-indicator { background: url(/abcprod/images/arrows-ffffff.png) no-repeat -10px -100px; }
Basically, I have the following so far: class Foo { public override bool Equals(object
I have the following code that basically is a input form as I have
i have following code in applet that basically writes some data to a file
i have the following jquery code. basically i will have several overlapped divs and
I have the following code: import os import csv listing = os.listdir('/directory/my/files/are/in') os.chdir('/directory/my/files/are/in') for
Basically I have the following code working, but i can not find a way
I have the following little import application, basically it... connects to a hosted SQL

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.