jchannel.channel

class Channel(server, code)

Represents a communication channel between a kernel server and a frontend client.

Parameters:
  • server (jchannel.server.Server) – The server.

  • code (str) – JavaScript code representing an initialization function. This function should receive a client Channel instance and initialize it.

property context_timeout

The context request timeout in seconds. Default is 3.

When this channel is used as a context manager, this timeout is passed to the open and close requests.

property handler

The object that handles calls from the client.

open(timeout=3)

Opens this channel.

Parameters:

timeout (int) – The request timeout in seconds.

Returns:

A task that can be awaited to obtain the return value of the initialization function.

Return type:

asyncio.Task

close(timeout=3)

Closes this channel.

Parameters:

timeout (int) – The request timeout in seconds.

Returns:

A task that can be awaited to ensure the closure is complete.

Return type:

asyncio.Task

echo(*args, timeout=3)

Sends arguments to the client and receives them back.

Under normal circumstances, this method should not be called. It should only be called for debugging or testing purposes.

It is particularly useful to verify whether the arguments are robust to JSON serialization and deserialization.

Parameters:
  • args – The arguments.

  • timeout (int) – The request timeout in seconds.

Returns:

A task that can be awaited to obtain the same arguments as a list.

Return type:

asyncio.Task[list]

pipe(stream, timeout=3)

Sends a byte stream to the client and receives it back.

Under normal circumstances, this method should not be called. It should only be called for debugging or testing purposes.

It is particularly useful to verify whether the bytes are robust to GET and POST streaming.

Parameters:
  • stream – An async iterable of bytes-like objects.

  • timeout (int) – The request timeout in seconds.

Returns:

A task that can be awaited to obtain the same bytes as a meta generator.

Return type:

asyncio.Task[jchannel.types.MetaGenerator]

call(name, *args, timeout=3)

Makes a call to the client.

Parameters:
  • name (str) – The name of a client handler method.

  • args – The arguments of the call.

  • timeout (int) – The request timeout in seconds.

Returns:

A task that can be awaited to obtain the return value of the method.

Return type:

asyncio.Task

call_with_stream(name, stream, *args, timeout=3)

Makes a call to the client with a byte stream as its first argument. The method receives it as a client MetaGenerator.

Parameters:
  • name (str) – The name of a client handler method.

  • stream – The first argument of the call, an async iterable of bytes-like objects.

  • args – The other arguments of the call.

  • timeout (int) – The request timeout in seconds.

Returns:

A task that can be awaited to obtain the return value of the method.

Return type:

asyncio.Task