Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Abandoned StreamWriter isn't reliably detected #114914

Closed
Labels
@CendioOssman

Description

@CendioOssman

Bug report

Bug description:

A StreamWriter should beclose():d when you are done with it. There is code in the destructor for StreamWriter to detect when this is overlooked and trigger aResourceWarning. However, the current code often maintains a strong reference to the writer, preventing it from being garbage collected and hence no warning.

Test case:

#!/usr/bin/python3importasyncioimportgcimportsocketasyncdefhandle_echo(reader,writer):addr=writer.get_extra_info('peername')print(f"Connection from{addr!r}")# Forgetting to close the writer#writer.close()#await writer.wait_closed()asyncdefmain():server=awaitasyncio.start_server(handle_echo,'127.0.0.1',8888)addrs=', '.join(str(sock.getsockname())forsockinserver.sockets)print(f'Serving on{addrs}')client=socket.create_connection(('127.0.0.1',8888))client.send(b'a'*64*1024)asyncwithserver:foriinrange(25):awaitasyncio.sleep(0.1)gc.collect()print('Exiting')print('Done serving')client.close()asyncio.run(main())

Test case locks up waiting for the client connection, when instead I would expect aResourceWarning and everything exiting nicely.

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp