Skip to content

Conversation

@tomMoral
Copy link
Contributor

@tomMoral tomMoral commented Mar 15, 2018

The Queue._feed does not properly handle the size of the Queue on errors. This can lead to a situation where the Queue is considered as Full when it is empty. Here is a reproducing script:

import multiprocessing as mp

q = mp.Queue(1)


class FailPickle():
    def __reduce__(self):
        raise ValueError()

q.put(FailPickle())
print("Queue is full:", q.full())
q.put(0)
print(f"Got result: {q.get()}")

This PR fixes this behavior.

https://bugs.python.org/issue33078

pitrou
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! A few comments below.

info('error in queue thread: %s', e)
return
else:
queue_sem.release()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment explaining why you need to adjust the semaphore's value?

q.put(NotSerializable())
q.put(True)
# bpo-30595: use a timeout of 1 second for slow buildbots
self.assertTrue(q.get(timeout=1.0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you add a check for q.qsize() as well?

@@ -0,0 +1,2 @@
Fix the size handeling in multiprocessing.Queue when a pickling error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "handling".

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

pitrou
q = self.Queue(maxsize=1)
q.put(NotSerializable())
q.put(True)
self.assertEqual(q.qsize(), 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check correct? Depending on when the worker thread triggers, it might return 2, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is correct because maxsize=1 so the second q.put should return only once the failure has been triggered.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, thank you.

@miss-islington
Copy link
Contributor

Thanks @pitrou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 21, 2018
(cherry picked from commit e2f33ad)

Co-authored-by: Thomas Moreau <[email protected]>
pitrou pushed a commit that referenced this pull request Mar 21, 2018
(cherry picked from commit e2f33ad)

Co-authored-by: Thomas Moreau <[email protected]>
jo2y pushed a commit to jo2y/cpython that referenced this pull request Mar 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant