Skip to content
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

copyfileobj doesn't support async file handles #12

Open
dj1471 opened this issue May 10, 2023 · 0 comments
Open

copyfileobj doesn't support async file handles #12

dj1471 opened this issue May 10, 2023 · 0 comments

Comments

@dj1471
Copy link

dj1471 commented May 10, 2023

I was attempting to use copyfileobj but found that it doesn't support async file handles. This makes the function essentially useless as you wouldn't want to use a standard file handle in an async application.

Sample code:

#!/usr/bin/env python3
import asyncio
from aiopath import AsyncPath
import aioshutil


async def test():
    a = AsyncPath('a.txt').open()
    b = AsyncPath('b.txt').open()
    await aioshutil.copyfileobj(a, b)

asyncio.run(test())

Which returns:

Traceback (most recent call last):
File "/home/user/venv/./test.py", line 12, in
asyncio.run(test())
File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/home/user/venv/./test.py", line 10, in test
await aioshutil.copyfileobj(a, b)
File "/home/user/venv/lib/python3.11/site-packages/aioshutil/init.py", line 205, in run_in_executor
return await loop.run_in_executor(None, pfunc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/shutil.py", line 194, in copyfileobj
fsrc_read = fsrc.read
^^^^^^^^^
AttributeError: '_AsyncGeneratorContextManager' object has no attribute 'read'

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

No branches or pull requests

1 participant