dabeaz / curio

Good Curio!
Other
4.04k stars 244 forks source link

how to wrap a file descriptor? #307

Closed yunfan closed 4 years ago

yunfan commented 4 years ago

hi i just found this powerful library.and i had noticed that there were async file read/write methods, but they were all bound to the async fileobj , so if i had a file descriptor , how could i wrap it into these async fileobj?

PS my file descriptor came from pty.openpty() in case you might say why not use your api to open the file and got the fileobj

kdart commented 4 years ago

You could use os.fdopen() to wrap the fd in a file object, then wrap that in a FileStream object.

dabeaz commented 4 years ago

Curio provides FileStream and AsyncFile classes for wrapping files. The choice depends on whether or not the underlying file natively supports non-blocking I/O.