0

Cannot realize why this simple code putting 1,2,3 into queue give me as many such errors (repeat it here as well https://repl.it/@coalesce/Where-s-Waldo)

File "/usr/local/lib/python3.7/multiprocessing/connection.py", line 368, in _send
    n = write(self._handle, buf)
BrokenPipeError: [Errno 32] Broken pipe

as values I trying to put. But just in case if I am trying to job_queue.close() (but after the queue seems to be empty).

And why these errors seems not to be catched with my except's? :/

import sys
from multiprocessing import Queue

def put_items_to_q(q, n):
    try:
      for i in range(n):
          q.put(i)
    except (BrokenPipeError, IOError) as e:
        sys.stdout.write("ERRROR HERE {} ? \n".format(e))
        pass

if __name__ == '__main__':

    sys.stdout.writelines( 'Starting\n')

    job_queue = Queue()

    put_items_to_q(job_queue, 3)

    while not job_queue.empty():
          try:
              job_queue.get(block=False)
          except (BrokenPipeError, IOError) as e:
              sys.stdout.write("OR ERRROR HERE? {} \n".format(e))
              break

    if job_queue.empty():
        sys.stdout.write("Q is empty\n")

        try:
          job_queue.close()
          job_queue.join_thread()
          pass
        except (BrokenPipeError, IOError) as e:
            sys.stdout.write("OR ERRROR HERE? {} \n".format(e))
            pass

    sys.stdout.write("End")
martineau
  • 119,623
  • 25
  • 170
  • 301
Dima Fomin
  • 1,228
  • 1
  • 16
  • 27
  • 1
    The code in your question isn't a [mre]. When I run it, no exceptions occur. Note this is probably because it never starts any other processes. Note I'm using Window. – martineau Nov 02 '19 at 00:23
  • @martineau Well, indeed, you are rigth! I just tried it on my Windows desktop and everything is ok. But you can see issues on repl.it by my link. As well on Google Colab Notebook, where I faced it. And even there errors occurs not each time, but one of two-three runs. May be this is case for containered environments only? :/ – Dima Fomin Nov 02 '19 at 07:28
  • Just a hunch, try changing the last line to `sys.stdout.write("End\n")`. – martineau Nov 02 '19 at 07:33

0 Answers0