You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 python3importasynciofromaiopathimportAsyncPathimportaioshutilasyncdeftest():
a=AsyncPath('a.txt').open()
b=AsyncPath('b.txt').open()
awaitaioshutil.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'
The text was updated successfully, but these errors were encountered:
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:
Which returns:
The text was updated successfully, but these errors were encountered: