Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asyncio version of `os.chmod` in Python

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?

like image 524
Tom Christie Avatar asked Jun 05 '17 15:06

Tom Christie


People also ask

How do I find the Asyncio version?

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.

How does Asyncio Python work?

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.

What is Asyncio event loop?

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.


1 Answers

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)
like image 148
Andrew Svetlov Avatar answered Oct 18 '22 18:10

Andrew Svetlov