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=[])
-
Start the server, making it listen a the port for incoming HTTP connections, calling previously registered URL and API handlers.
-
When the server is started from
hython
whenin_background
is not True, you can stop it by pressing ⌃ Ctrl + C (Linux and Mac) or ⌃ Ctrl + Break/⌃ Ctrl + ScrLk on Windows in the terminal.
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 |