-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[3.12] GH-106684: Close asyncio.StreamWriter
when asyncio.StreamWriter
is not closed by application (GH-107650)
#107656
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
Conversation
…is not closed (pythonGH-107650) (cherry picked from commit 41178e4) Co-authored-by: Kumar Aditya <[email protected]>
I think this should go into rc2, but without the warning. I think the warning is too potentially disruptive this late in the release cycle. |
a16f262
to
02429ce
Compare
ResourceWarning
when asyncio.StreamWriter
is not closed (GH-107650)asyncio.StreamWriter
when asyncio.StreamWriter
is not closed by application (GH-107650)
Thanks @miss-islington for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
GH-107836 is a backport of this pull request to the 3.11 branch. |
…reamWriter` is not closed by application (pythonGH-107650) (pythonGH-107656) pythonGH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (pythonGH-107650) (cherry picked from commit 41178e4) (cherry picked from commit 7853c76) Co-authored-by: Miss Islington (bot) <[email protected]> Co-authored-by: Kumar Aditya <[email protected]> Co-authored-by: Kumar Aditya <[email protected]>
…treamWriter` is not closed by application (GH-107650) (GH-107656) (#107836) [3.12] GH-106684: Close `asyncio.StreamWriter` when `asyncio.StreamWriter` is not closed by application (GH-107650) (GH-107656) GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (GH-107650) (cherry picked from commit 41178e4) (cherry picked from commit 7853c76) Co-authored-by: Kumar Aditya <[email protected]>
It seems that closing the connection in the StreamWriter's import asyncio
HOST = 'ifconfig.me'
PORT = 80
async def connect() -> asyncio.Transport:
reader, writer = await asyncio.open_connection(
host=HOST,
port=PORT,
)
return writer.transport
async def fetch():
loop = asyncio.get_running_loop()
transport = await connect()
# !!! transport is already closed here after this PR merged
reader = asyncio.StreamReader(limit=2**16, loop=loop)
protocol = asyncio.StreamReaderProtocol(reader, loop=loop)
transport.set_protocol(protocol)
loop.call_soon(protocol.connection_made, transport)
loop.call_soon(transport.resume_reading)
writer = asyncio.StreamWriter(
transport=transport,
protocol=protocol,
reader=reader,
loop=loop,
)
request = f'GET /ip HTTP/1.1\r\nHost: {HOST}\r\nConnection: close\r\n\r\n'.encode()
writer.write(request)
await writer.drain()
response = await reader.read(-1)
print(response)
if __name__ == '__main__':
asyncio.run(fetch()) |
(cherry picked from commit 41178e4)
Co-authored-by: Kumar Aditya [email protected]