gevent.fileobject
– Wrappers to make file-like objects cooperative¶FileObject
¶The main entry point to the file-like gevent-compatible behaviour. It will be defined to be the best available implementation.
There are two main implementations of FileObject
. On all systems,
there is FileObjectThread
which uses the built-in native
threadpool to avoid blocking the entire interpreter. On UNIX systems
(those that support the fcntl
module), there is also
FileObjectPosix
which uses native non-blocking semantics.
A third class, FileObjectBlock
, is simply a wrapper that executes everything
synchronously (and so is not gevent-compatible). It is provided for testing and debugging
purposes.
You may change the default value for FileObject
using the
GEVENT_FILE
environment variable. Set it to posix
, thread
,
or block
to choose from FileObjectPosix
,
FileObjectThread
and FileObjectBlock
, respectively.
You may also set it to the fully qualified class name of another
object that implements the file interface to use one of your own
objects.
Note
The environment variable must be set at the time this module is first imported.
FileObjectPosix
(fobj, mode='rb', bufsize=-1, close=True)¶Bases: object
A file-like object that operates on non-blocking files.
See also
gevent.os.make_nonblocking()
Parameters: | fobj – Either an integer fileno, or an object supporting the
usual socket.fileno() method. The file will be
put in non-blocking mode. |
---|
closed
¶True if the file is cloed
default_bufsize
= 8192¶close
()¶flush
()¶fileno
()¶write
(data)¶writelines
(lines)¶read
(size=-1)¶readline
(size=-1)¶readlines
(sizehint=0)¶readable
()¶writable
()¶seek
(*args, **kwargs)¶seekable
()¶tell
()¶truncate
(size=None)¶FileObjectThread
(fobj, *args, **kwargs)¶Bases: object
A file-like object wrapping another file-like object, performing all blocking operations on that object in a background thread.
Parameters: |
|
---|
close
()¶flush
(_fobj=None)¶next
()¶read
(*args, **kwargs)¶readinto
(*args, **kwargs)¶readline
(*args, **kwargs)¶readlines
(*args, **kwargs)¶write
(*args, **kwargs)¶writelines
(*args, **kwargs)¶xreadlines
(*args, **kwargs)¶FileObject
alias of FileObjectPosix
Next page: gevent.local
– Greenlet-local objects