Pyjo.IOLoop.Stream - Non-blocking I/O stream

import Pyjo.IOLoop.Stream

# Create stream
with Pyjo.IOLoop.Stream.new(handle) as stream:

    @stream.on
    def read(stream, chunk):
        ...

    @stream.on
    def close(stream):
        ...

    @stream.on
    def error(stream, err):
        ...

    # Start and stop watching for new data
    stream.start()
    stream.stop()

    # Start reactor if necessary
    if not stream.reactor.is_running:
        stream.reactor.start()

Pyjo.IOLoop.Stream is a container for I/O streams used by Pyjo.IOLoop.

Events

Pyjo.IOLoop.Stream inherits all events from Pyjo.IOLoop.EventEmitter and can emit the following new ones.

close

@stream.on
def close(stream):
    ...

Emitted if the stream gets closed.

drain

@stream.on
def drain(stream):
    ...

Emitted once all data has been written.

error

@stream.on
def error(stream, err):
    ...

Emitted if an error occurs on the stream, fatal if unhandled.

read

@stream.on
def read(stream, chunk):
    ...

Emitted if new data arrives on the stream.

timeout

@stream.on
def timeout(stream):
    ...

Emitted if the stream has been inactive for too long and will get closed automatically.

write

@stream.on
def write(stream, chunk):
    ...

Emitted if new data has been written to the stream.

Classes

class Pyjo.IOLoop.Stream.Pyjo_IOLoop_Stream(handle, *args, **kwargs)

Pyjo.IOLoop.Stream inherits all attributes and methods from Pyjo.EventEmitter and implements the following new ones.

close()
stream.close()

Close stream immediately. Used by context manager.

close_gracefully()
stream.close_gracefully()

Close stream gracefully.

fd
fd = stream.fd

Number of descriptor for handle

handle = None
handle = stream.handle

Handle for stream.

is_readable
boolean = stream.is_readable

Quick non-blocking check if stream is readable, useful for identifying tainted sockets.

is_writing
boolean = stream.is_writing

Check if stream is writing.

reactor = None
reactor = stream.reactor
stream.reactor = Pyjo.Reactor.Poll.new()

Low-level event reactor, defaults to the reactor attribute value of the global Pyjo.IOLoop singleton.

start()
stream.start()

Start watching for new data on the stream.

steal_handle()
handle = stream.steal_handle()

Steal handle from stream and prevent it from getting closed automatically.

stop()
stream.stop()

Stop watching for new data on the stream.

timeout
timeout = stream.timeout
stream.timeout = 45

Maximum amount of time in seconds stream can be inactive before getting closed automatically, defaults to 15. Setting the value to 0 will allow this stream to be inactive indefinitely.

write(chunk, cb=None)
stream = stream.write(bstring)
stream = stream.write(bstring, cb)

Write data to stream, the optional drain callback will be invoked once all data has been written.

Pyjo.IOLoop.Stream.object

alias of Pyjo_IOLoop_Stream