-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Concurrent drains #1915
Concurrent drains #1915
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import collections | ||
import socket | ||
import zlib | ||
from collections import deque | ||
from urllib.parse import SplitResult | ||
|
||
import yarl | ||
|
@@ -39,6 +40,8 @@ def __init__(self, protocol, transport, loop): | |
self._waiters = [] | ||
self.available = True | ||
self.transport = transport | ||
self._is_drain = False | ||
self._drain_waiters = deque() | ||
|
||
def acquire(self, writer): | ||
if self.available: | ||
|
@@ -125,7 +128,18 @@ def drain(self): | |
yield from w.drain() | ||
""" | ||
if self._protocol.transport is not None: | ||
yield from self._protocol._drain_helper() | ||
if self._is_drain: | ||
fut = asyncio.Future(loop=self._loop) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we use same future for all callers? |
||
self._drain_waiters.append(fut) | ||
yield from fut | ||
self._is_drain = True | ||
try: | ||
yield from self._protocol._drain_helper() | ||
finally: | ||
self._is_drain = False | ||
if self._drain_waiters: | ||
fut = self._drain_waiters.popleft() | ||
fut.set_result(None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same "deadlock" issue (a,b) can happen here: if future on line 134 is cancelled then other task that a: bugs.python.org/issue27585 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think cancellation tests should be added as well. |
||
|
||
|
||
class PayloadWriter(AbstractPayloadWriter): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._loop.create_future()
I guess