Pipe — Named pipe handle

class pyuv.Pipe(loop, ipc)
Parameters:
  • loop (Loop) – loop object where this handle runs (accessible through Pipe.loop).
  • ipc (boolean) – Indicate if this Pipe will be used for IPC connection.

The Pipe handle provides asynchronous named pipe functionality both as a client and server, supporting cross-process communication and handle sharing.

bind(name)
Parameters:name (string) – Name of the pipe to bind to.

Bind to the specified pipe name. The Pipe handle is acting as a server in this case.

listen(callback[, backlog])
Parameters:
  • callback (callable) – Callback to be called on every new connection. accept() should be called in that callback in order to accept the incoming connection.
  • backlog (int) – Indicates the length of the queue of incoming connections. It defaults to 511.

Start listening for new connections.

Callback signature: callback(pipe_handle, error).

open(fd)
Parameters:fd (int) – File descriptor to be opened.

Open the given file descriptor (or HANDLE in Windows) as a Pipe.

..note::
The file descriptor will be closed when the UDP handle is closed, so if it was tasken from a Python socket object, it will be useless afterwards.

Note

Once a file desctiptor has been passed to the open function, the handle ‘owns’ it. When calling close() on the handle, the file descriptor will be closed. If you’d like to keep using it afterwards it’s recommended to duplicate it (using os.dup) before passing it to this function.

Note

The fd won’t be put in non-blocking mode, the user is responsible for doing it.

accept(client)
Parameters:client (object) – Client object where to accept the connection.

Accept a new incoming connection which was pending. This function needs to be called in the callback given to the listen() function or in the callback given to the start_read2() is there is any pending handle.

connect(name, callback)
Parameters:
  • name (string) – Name of the pipe to connect to.
  • callback (callable) – Callback to be called when the connection to the remote endpoint has been made.

Initiate a client connection to the specified named pipe.

Callback signature: callback(pipe_handle, error).

shutdown([callback])
Parameters:callback (callable) – Callback to be called after shutdown has been performed.

Shutdown the outgoing (write) direction of the Pipe connection.

Callback signature: callback(pipe_handle, error).

write(data[, callback[, handle]])
Parameters:
  • data (object) – Data to be written on the Pipe connection. It can be any Python object conforming to the buffer interface or a sequence of such objects.
  • callback (callable) – Callback to be called after the write operation has been performed.
  • handle (object) – Handle to send over the Pipe. Currently only TCP, UDP and Pipe handles are supported.

Write data on the Pipe connection.

Callback signature: callback(tcp_handle, error).

try_write(data)
Parameters:data (object) – Data to be written on the Pipe connection. It can be any Python object conforming to the buffer interface.

Try to write data on the Pipe connection. It will raise an exception if data cannot be written immediately or a number indicating the amount of data written.

start_read(callback)
Parameters:callback (callable) – Callback to be called when data is read from the remote endpoint.

Start reading for incoming data from the remote endpoint.

Callback signature: callback(pipe_handle, data, error).

start_read2(callback)
Parameters:callback (callable) – Callback to be called when data is read from the remote endpoint.

Start reading for incoming data or a handle from the remote endpoint.

Callback signature: callback(pipe_handle, data, pending, error).

stop_read()

Stop reading data from the remote endpoint.

pending_instances(count)
Parameters:count (int) – Number of pending instances.

This setting applies to Windows only. Set the number of pending pipe instance handles when the pipe server is waiting for connections.

fileno()

Return the internal file descriptor (or HANDLE in Windows) used by the Pipe handle.

Warning

libuv expects you not to modify the file descriptor in any way, and if you do, things will very likely break.

send_buffer_size

Gets / sets the send buffer size.

receive_buffer_size

Gets / sets the receive buffer size.

write_queue_size

Read only

Returns the size of the write queue.

readable

Read only

Indicates if this handle is readable.

writable

Read only

Indicates if this handle is writable.