Pipe — Named pipe handle

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

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 Pipe 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 when the remote endpoint has shared a handle using the handle argument of write(). In either case the method pending_handle_type() tells you the type of handle to pass as the client argument.

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).

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.

pending_handle_type()

Return the type of handle that is pending. The possible return values are UV_TCP, UV_UDP and UV_NAMED_PIPE, corresponding to a TCP, a UDP and a Pipe handle respectively. The special value UV_UNKNOWN_HANDLE means no handle is pending.

There are two situations when a handle becomes pending: a new connection is available on a listening socket, or a handle was shared by the remote endpoint using the handle argument to write().

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.

ipc

Read only

Indicates if this pipe is enabled for sharing handles.

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.