teachbooks.serve module

Serve a teachbook locally.

class teachbooks.serve.Server(servedir: Path | str, workdir: Path | str, port: int | None = None, stdout: int | None = None)

Bases: object

Class for managing a Python webserver in the background.

property is_running: bool

Check if the current process ID is a running webserver.

Returns:

True if the current process ID is running and is a webserver.

classmethod load(workdir: Path | str) Server_t

Construct a Server object from an existing pickle file.

Parameters:

workdir – Directory containing the pickle file.

Returns:

Server object reconstructed from pickle file.

Raises:

ServerError – If pickle file cannot be found.

start(options: list[str] = None) bool

Start server.

Raises:

RuntimeError – If server could not be started

statefile = 'state.pickle'
stop(options: list[str] = None) None

Stop server and clean up.

property url: str

Get URL of running server.

Returns:

URL of the server.

exception teachbooks.serve.ServerError

Bases: Exception

Server exception class.