Houdini 19.0 hwebserver

hwebserver.run function

Starts Houdini’s web server.

run(port=8008, debug=False, max_num_threads=4, in_background=None, reload_source_changes=None, max_in_memory_file_upload_size=None, max_request_size=None, settings=None, ports=[])

port

The port number to listen on. If this port is already in use or the process does not have permission to listen on it, the function raises hwebserver.OperationFailed.

debug

If this is True, the server writes console log messages and displays stack traces for Python exceptions raised when handling requests. It also returns the stack traces in response bodies.

When running in hython, this also sets reload_source_changes to True.

You can check if the server is running in debug mode using hwebserver.isInDebugMode.

max_num_threads

The maximum number of simultaneous worker threads created to handle concurrent requests.

Any calls in the hwebserver package acquire a global lock, and Python handler functions must acquire the GIL, so handlers cannot usually run concurrently. The main speed benefit of multithreading comes when serving static files or making blocking I/O operations from Python that do not involve Houdini.

in_background

Whether the function should start the server in a separate thread. If you pass in_background=False, this function will never return unless the server is interrupted or server code calls hwebserver.requestShutdown.

If in_background is None (the default value), it will be set to True in a graphical Houdini session and False otherwise.

reload_source_changes

If this is True, the server monitors all loaded Python source files and restarts the server whenever any of them change. This lets you edit your Python code and see the results without needing to stop and restart the server manually.

max_in_memory_file_upload_size

The maximum size, in bytes, of uploaded files that will be kept in RAM rather than written to a temp file. By default, the server will keep uploaded files that are less than 2.5 MB in memory, but write files larger than that to disk. This argument lets you override that threshold.

max_request_size

The maximum size of an HTTP request, in bytes. If this is None, the default value is 3 GB.

settings

Specify the settings file to add extra settings to the web server. Currently this only allows you to specify the CORS whitelist. This works similarly to djangos settings file.

ports

The extra ports the server should listen on.

verbosity

The verbosity of the server. The default settings is low.

port_callback

If the program needs to know the actual port number the server is running on a port callback can be used to retrieve the actual port number. It is not recommended to use this callback as an initialization function as there is no guarantee made on where in the initialization stage this callback will be called.

up_to_port

If the port number from the port parameter failed to listen then try every port up to this parameters port number. As an example, if the port number is 80 and this parameter is 90, then every port from 81-90 will be tried before giving up. The first port in this range that is able to listen to will be used as the main port for the server.

use_free_port_on_failure

If the port range and initial port both fail to find a free port then let the OS pick a free port. This parameter can be used instead of the port range if the server just needs to find a free port with little care about the actual port number.

See also

hwebserver

クラス

開始と停止

ウェブリクエストの処理とレスポンスの返し

ウェブソケット

  • WebSocket

    Base class for WebSocket support with the embedded server.

  • hwebserver.webSocket

    Decorator for registering WebSocket classes with Houdini’s web server.

APIコール

  • hwebserver.apiFunction

    Decorator for functions that can be called through an API endpoint on Houdini’s web server, returning JSON or binary responses.

  • hwebserver.APIError

    Raise this exception in apiFunction handlers to indicate an error.