-
-
Notifications
You must be signed in to change notification settings - Fork 149
-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more os calls like os.stat #4
Comments
If someone were to submit quality pull requests (with tests, of course) I wouldn't be opposed to merging them in. :) |
@Tinche Do you have a preference for what aiofiles module |
@cjerdonek I guess |
havn't fully tested yet, but should this snippet work? import asyncio
import inspect
from functools import wraps, partial
def wrap(func):
@wraps(func)
async def run(*args, loop=None, executor=None, **kwargs):
if loop is None:
loop = asyncio.get_event_loop()
pfunc = partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, pfunc)
return run
class Wrapper:
pass
def aiowrap(obj):
if callable(obj):
return wrap(obj)
elif inspect.ismodule(obj) or inspect.isclass(obj):
wrapped_obj = Wrapper()
if getattr(obj, '__all__'):
attrnames = obj.__all__
else:
attrnames = dir(obj)
for attrname in attrnames:
if attrname.startswith('__'):
continue
original_obj = getattr(obj, attrname)
setattr(wrapped_obj, attrname, aiowrap(original_obj))
return wrapped_obj
else:
return obj Usage import os
from aiowrap import aiowrap
aios = aiowrap(os)
async def main():
print(await aios.path.exists('/'))
if __name__ == '__main__':
import asyncio as aio
loop = aio.get_event_loop()
loop.run_until_complete(main()) |
Support for |
How do you even use aiofiles.os, when I try I get |
@Qwerty-Space Use |
|
would be nice to add support for os.listdir |
|
os.fstat is missing |
Bump.. |
I'm just poking at this - came to it through a reference on MagicStack/uvloop#1 (comment)
Would you be interested in adding support to the project for more calls from the os module like
os.stat
?e.g.
os.close
os.fstat
os.read
os.write
os.unlink
os.listdir
os.path.exists
os.rmdir
The text was updated successfully, but these errors were encountered: