Tinche / aiofiles

File support for asyncio
Apache License 2.0
2.88k stars 153 forks source link

not found function #149

Closed Chasikanaft closed 2 years ago

Chasikanaft commented 2 years ago

aiofiles.os.sendfiles not found. Error: AttributeError: module 'aiofiles.os' has no attribute 'sendfile'

pip freeze result:

aiofiles==22.1.0
asyncio==3.4.3
types-aiofiles==22.1.0

or another method copy file to dir like a link? im newbie of python

Chasikanaft commented 2 years ago

aiofiles.os.sendfiles not found. Error: AttributeError: module 'aiofiles.os' has no attribute 'sendfile'

pip freeze result:

aiofiles==22.1.0
asyncio==3.4.3
types-aiofiles==22.1.0

or another method copy file to dir like a link? im newbie of python

so Python version - 3.9.4

Tinche commented 2 years ago

Try aiofiles.io.sendfile instead of sendfiles? Sendfile is an advanced function though, definitely not for newbies. Not sure what you're trying to accomplish.

Chasikanaft commented 2 years ago

Try aiofiles.io.sendfile instead of sendfiles? Sendfile is an advanced function though, definitely not for newbies. Not sure what you're trying to accomplish.

aiofiles.io.sendfile not found too. Its seems to be right, copy buffer with read() function andwrite()to destination file?

Tinche commented 2 years ago

Er sorry, it's aiofiles.os.sendfile.

But for simple file copying, you can look at https://docs.python.org/3/library/shutil.html#shutil.copyfile. We don't have an async version of that, so you'll have to run it in a background thread yourself, something like: asyncio.get_running.loop().run_in_executor(None, shutil.copyfile, arg1, arg2)

Chasikanaft commented 2 years ago

Thanks! can you tell me how to call this function so that it does not block the main thread? the call is made from a synchronous function?)

Tinche commented 2 years ago

You use run_in_executor like in my snippet. That'll run it in a thread

Chasikanaft commented 2 years ago

RuntimeError: no running event loop error, I think this error is caused by the fact that my function from which I have to call the copy method belongs to a class (not asynchronous). Can you suggest how to do it right? I need to call in parallel the functions of copying and viewing the status of copied files (stats) for the progress bar status

Tinche commented 2 years ago

Hey, this is getting out of scope for this project now. You should try stack overflow!