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?
How to check my asyncio version on Windows? To check which version of asyncio is installed, use pip show asyncio or pip3 show asyncio in your Windows CMD, command line, or PowerShell.
asyncio is a library to write concurrent code using the async/await syntax. asyncio is used as a foundation for multiple Python asynchronous frameworks that provide high-performance network and web-servers, database connection libraries, distributed task queues, etc.
The event loop is the core of every asyncio application. Event loops run asynchronous tasks and callbacks, perform network IO operations, and run subprocesses. Application developers should typically use the high-level asyncio functions, such as asyncio.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With