Issue
I have some Python3 code running inside an asyncio
event loop.
I want to use the functionality of os.chmod(...)
, but would ideally like a non-blocking version of this, so that I can use await os.chmod(...)
, and avoid making a blocking system call.
I don't believe there any libraries available that supply this functionality yet, at least from what I can see.
How would I go about implementing a non-blocking os.chmod(...)
from scratch? Better still, is there a pre-existing solution?
Solution
UNIX systems have not implemented an asynchronous API for the chmod
syscall.
Thus the best you can do is run it in a thread pool:
await loop.run_in_executor(None, os.chmod, fname, mode)
Answered By - Andrew Svetlov Answer Checked By - Dawn Plyler (WPSolving Volunteer)