Skip to content

Feature/clone function#86

Merged
mosquito merged 1 commit into
masterfrom
feature/clone-function
May 16, 2026
Merged

Feature/clone function#86
mosquito merged 1 commit into
masterfrom
feature/clone-function

Conversation

@mosquito
Copy link
Copy Markdown
Owner

@mosquito mosquito commented Aug 18, 2023

This pull request introduces a new asynchronous file cloning feature to the aiofile library, allowing multiple independent file-like objects to share a single file descriptor with separate offsets. This enables concurrent reading (and potentially writing) from the same file without reopening it, which can improve performance in certain scenarios. The change includes a new clone helper, updates to the core AIOFile class, and corresponding tests and documentation.

New file cloning feature:

  • Added a clone helper function and FileIOCloner class to aiofile.utils, allowing users to create independent file-like clones from an existing file object. This enables concurrent operations with separate offsets on the same file descriptor.
  • Updated the public API in aiofile/__init__.py to export clone and FileIOCloner. [1] [2] [3]

Core class enhancements:

  • Modified the AIOFile class to support reference counting for clones, ensuring the file is only closed when all clones are released. Added a clone() async method and internal locking for thread safety. [1] [2]

Documentation:

  • Added a new section to README.md explaining the clone helper, including a practical example and caveats for Windows users.

Testing:

  • Added new tests in tests/test_aio.py to verify the behavior of file cloning, including correct reading, offset handling, and reference-counted closing. [1] [2]

Comment thread aiofile/utils.py
@mosquito mosquito force-pushed the feature/clone-function branch from dd52463 to cda62fa Compare August 22, 2023 12:49
AIOFile.clone() bumps a ref-count so close() is deferred until all clones
are released. FileIOCloner wraps this for the high-level async_open wrappers.
@mosquito mosquito force-pushed the feature/clone-function branch from 38cb295 to 0c2f547 Compare May 16, 2026 07:06
@mosquito mosquito merged commit 9b77e74 into master May 16, 2026
15 checks passed
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.

2 participants