Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

23 строки
514 B

  1. """Async executor versions of file functions from the os module."""
  2. import asyncio
  3. from functools import partial, wraps
  4. import os
  5. def wrap(func):
  6. @asyncio.coroutine
  7. @wraps(func)
  8. def run(*args, loop=None, executor=None, **kwargs):
  9. if loop is None:
  10. loop = asyncio.get_event_loop()
  11. pfunc = partial(func, *args, **kwargs)
  12. return loop.run_in_executor(executor, pfunc)
  13. return run
  14. stat = wrap(os.stat)
  15. if hasattr(os, "sendfile"):
  16. sendfile = wrap(os.sendfile)