Skip to content

trio.wrap_file() undocumented behavior wrt to sync file object #3379

Open

Description

@Nikratio

Hello,

Looking at https://trio.readthedocs.io/en/stable/reference-io.html#trio.wrap_file, it is not clear to me if:

  • Closing the returned async file object will also close the sync file object that I passed in
  • Whether this will happen automatically when the async file object is garbage collected
  • If I can continue to use the sync file object at the same time.

It'd be great if that could be clarified!

Activity

  1. A5rocks commented on Jan 18, 2026

    @A5rocks
    Contributor

    Looking at the code (so actually testing these behaviors may show I'm wrong), I believe this is yes, no, yes.

    I think the 1st and 3rd are somewhat implied by the docs talking about this being a wrapper (... it basically just sends sync ops to a thread pool) but we could definitely be more explicit about the implications of that. And also more explicit about where we diverge from standard behavior, like not having a destructor.

  2. nightcityblade commented on Apr 13, 2026

    @nightcityblade

    Hi, I'd like to work on this. I'll submit a PR shortly.

  3. added a commit that references this issue on Apr 13, 2026
    3e94e40
  4. changed the title [-]trip.wrap_file() undocumented behavior wrt to sync file object[/-] [+]trio.wrap_file() undocumented behavior wrt to sync file object[/+] on Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions