Skip to content

Platform

Platform object is available in uwsgi module attribute:

from uwsgiconf.runtime.platform import uwsgi

rss, vsz = uwsgi.memory

print(uwsgi.config)

@uwsgi.postfork_hooks.add()
def db_close_connections():
    """This will be called after fork()."""
    print('Forked!')

_Platform

_Platform()

Attributes

apps_map

.apps_map: dict | None = _uwsgi.applications

Applications dictionary mapping mountpoints to application callables.


buffer_size

.buffer_size: int = _uwsgi.buffer_size

The current configured buffer size in bytes.


clock

.clock()

Returns uWSGI clock microseconds.


config

.config()

The current configuration options, including any custom placeholders.


config_variables

.config_variables()

Current mapping of configuration file "magic" variables.


cores_count

.cores_count: int = _uwsgi.cores

Detected number of processor cores.


hostname

.hostname()

Current host name.


master_pid

.master_pid()

Return the process identifier (PID) of the uWSGI master process.


memory

.memory()

Returns memory usage tuple of ints: (rss, vsz).


postfork_hooks

.postfork_hooks = _PostForkHooks

uWSGI is a preforking server, so you might need to execute a fixup tasks (hooks) after each fork(). Each hook will be executed in sequence on each process (worker/mule).

Note

The fork() happen before app loading, so there's no hooks for dynamic apps. But one can still move postfork hooks in a .py file and import it on server startup with python.import_module().


ready_for_requests

.ready_for_requests()

Returns flag indicating whether we are ready to handle requests.


request

.request: type[_Request] = _Request

Current request information.

Note

Object is attached runtime.


started_on

.started_on: int = _uwsgi.started_on

uWSGI's startup Unix timestamp.


threads_enabled

.threads_enabled: bool = _uwsgi.has_threads

Flag indicating whether thread support is enabled.


worker_id

.worker_id()

Returns current worker ID. 0 if not a worker (e.g. mule).


workers_count

.workers_count: int = _uwsgi.numproc

Number of workers (processes) currently running.


workers_info

.workers_info()

Gets statistics for all the workers for the current server.

Returns tuple of dicts.


Functions

get_listen_queue

1
2
3
.get_listen_queue(
    socket_num: int = 0,  # (1)!
) -> int
  1. Socket number.

Returns listen queue (backlog size) of the given socket.

ValueError If socket is not found


get_version

1
2
3
.get_version(
    as_tuple: bool = False
) -> str | tuple[int, int, int, int, str]

Returns uWSGI version string or tuple.


_Request

_Request()

Current request information.


Attributes

content_length

.content_length()

Returns current post content length.


env

.env()

Request environment dictionary.


fd

.fd()

Returns current request file descriptor.


id

.id()

Returns current request number (handled by worker on core).


total_count

.total_count()

Returns the total number of requests managed so far by the pool of uWSGI workers.


Functions

add_var

.add_var(name: str, value: str) -> bool

Registers custom request variable.

Can be used for better integration with the internal routing subsystem.

ValueError If buffer size is not enough.


log

.log()

Instructs uWSGI to log current request data.