7

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?

Tom Christie
  • 33,394
  • 7
  • 101
  • 86
  • For context, I'm implementing a Gunicorn worker process, that uses asyncio. Gunicorn uses a spinning `fchmod` status for signalling worker process aliveness. https://github.com/benoitc/gunicorn/blob/master/gunicorn/workers/workertmp.py – Tom Christie Jun 05 '17 at 15:56

1 Answers1

7

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)
davidism
  • 121,510
  • 29
  • 395
  • 339
Andrew Svetlov
  • 16,730
  • 8
  • 66
  • 69