Python uwsgi module stub¶
uwsgiconf comes with documented uwsgi module that you can import
instead of import uwsgi.
That way uwsgi will be available runtime as usual, besides you will
get autocompletion and hints in IDE, and won't get ImportError when
run without uwsgi.
This also will facilitate your testing a bit, for those simple cases when you won't expect any result from uwsgi function.
Tip
This is a stub module, so it doesn't fully implement functions defined in it. Yet it tries to emulate uWSGI to some extent to facilitate testing. Use it for testing and documentation purposes.
uwsgi.is_stub¶
You can check runtime whether you're using a stub:
Forcing stub¶
Sometimes (e.g. for tests but when uWSGI module is available) you may want to force stub.
That could be done with the help of UWSGICONF_FORCE_STUB environment variable:
Attributes¶
SPOOL_IGNORE¶
Spooler function result.
Ignore this task, if multiple languages are loaded in the instance all of them will fight for managing the task. This return values allows you to skip a task in specific languages.
SPOOL_OK¶
Spooler function result.
The task has been completed, the spool file will be removed.
SPOOL_RETRY¶
Spooler function result.
Something is temporarily wrong, the task will be retried at the next spooler iteration.
SymbolsImporter¶
SymbolsImporter type.
SymbolsZipImporter¶
SymbolsZipImporter type.
ZipImporter¶
ZipImporter type.
applications¶
Applications dictionary mapping mountpoints to application callables.
Note
Can be None.
buffer_size¶
The current configured buffer size in bytes.
cores¶
Detected number of processor cores.
env¶
Request environment dictionary.
has_threads¶
Flag indicating whether thread support is enabled.
hostname¶
Current host name.
is_stub¶
Indicates whether stub is used instead of real uwsgi module.
magic_table¶
Current mapping of configuration file "magic" variables.
mule_msg_hook¶
Registers a function to be called for each mule message.
numproc¶
Number of workers (processes) currently running.
opt¶
The current configuration options, including any custom placeholders.
post_fork_hook¶
Function to be called after process fork (spawning a new worker/mule).
sockets¶
Current list of file descriptors for registered sockets.
spooler¶
Function to be called for spooler messages processing.
start_response¶
Callable spitting UWSGI response.
started_on¶
uWSGI's startup Unix timestamp.
unbit¶
Unbit internal flag.
version¶
The uWSGI version string.
version_info¶
Five-elements version number tuple.
Functions¶
accepting¶
Called to notify the master that the worker is accepting requests,
this is required for touch_chain_reload to work.
add_cron¶
-
Signal to raise.
-
Minute 0-59. Defaults to
each. -
Hour 0-23. Defaults to
each. -
Day of the month number 1-31. Defaults to
each. -
Month number 1-12. Defaults to
each. -
Day of a the week number. Defaults to
each. 0 - Sunday 1 - Monday 2 - Tuesday 3 - Wednesday 4 - Thursday 5 - Friday 6 - Saturday
Adds cron. The interface to the uWSGI signal cron facility. The syntax is
Note
The last 5 arguments work similarly to a standard crontab, but instead of "*", use -1, and instead of "/2", "/3", etc. use -2 and -3, etc.
ValueError If unable to add cron rule.
add_file_monitor¶
-
Signal to raise.
-
File or a directory to watch for its modification.
Maps a specific file/directory modification event to a signal.
ValueError If unable to register monitor.
add_ms_timer¶
-
Signal to raise.
-
The interval (milliseconds) at which to raise the signal.
Add a millisecond resolution timer.
ValueError If unable to add timer.
add_rb_timer¶
-
Signal to raise.
-
The interval (seconds) at which the signal is raised.
-
How many times to send signal. Will stop after the number is reached. Default: 0 - infinitely.
Add a red-black timer.
ValueError If unable to add timer.
add_timer¶
-
Signal to raise.
-
The interval (seconds) at which to raise the signal.
Add timer.
ValueError If unable to add timer.
add_var¶
Registers custom request variable.
Can be used for better integration with the internal routing subsystem.
ValueError If buffer size is not enough.
alarm¶
- Message to pass to alarm.
Issues the given alarm with the given message.
Note
to register an alarm use
section.alarms.register_alarm(section.alarms.alarm_types.log('myalarm'))
async_connect¶
Issues socket connection. And returns a file descriptor or -1.
async_sleep¶
- Sleep time, in seconds.
Suspends handling the current request and passes control to the next async core.
cache_clear¶
- Cache name with optional address (if @-syntax is used).
Clears cache with the given name.
cache_dec¶
-
Expire timeout (seconds).
-
Cache name with optional address (if @-syntax is used).
Decrements the specified key value by the specified value.
cache_del¶
-
The cache key to delete.
-
Cache name with optional address (if @-syntax is used).
Deletes the given cached key from the cache.
cache_div¶
-
Expire timeout (seconds).
-
Cache name with optional address (if @-syntax is used).
Divides the specified key value by the specified value.
cache_exists¶
-
The cache key to check.
-
Cache name with optional address (if @-syntax is used).
Checks whether there is a value in the cache associated with the given key.
cache_get¶
-
The cache key to get value for.
-
Cache name with optional address (if @-syntax is used).
Gets a value from the cache.
cache_inc¶
-
Expire timeout (seconds).
-
Cache name with optional address (if @-syntax is used).
Increments the specified key value by the specified value.
cache_keys¶
Returns a list of keys available in cache.
ValueError If cache is unavailable.
cache_mul¶
-
Expire timeout (seconds).
-
Cache name with optional address (if @-syntax is used).
Multiplies the specified key value by the specified value.
cache_num¶
-
The cache key to get value for.
-
Cache name with optional address (if @-syntax is used).
Gets the 64bit number from the specified item.
cache_set¶
-
Expire timeout (seconds).
-
Cache name with optional address (if @-syntax is used).
Sets the specified key value.
cache_update¶
-
Expire timeout (seconds).
-
Cache name with optional address (if @-syntax is used).
Updates the specified key value.
call¶
- Function name to call with optional address (if @-syntax is used).
Performs an [RPC] function call with the given arguments.
chunked_read¶
- Wait timeout (seconds).
Reads chunked input.
- http://uwsgi.readthedocs.io/en/latest/Chunked.html
- http://uwsgi.readthedocs.io/en/latest/Changelog-1.9.13.html#chunked-input-api
IOError If unable to receive chunked part.
chunked_read_nb¶
Reads chunked input without blocking.
- http://uwsgi.readthedocs.io/en/latest/Chunked.html
- http://uwsgi.readthedocs.io/en/latest/Changelog-1.9.13.html#chunked-input-api
IOError If unable to receive chunked part.
cl¶
Returns current post content length.
close¶
connect¶
-
Socket name.
-
Timeout (seconds).
Connects to the socket.
connection_fd¶
Returns current request file descriptor.
disconnect¶
Drops current connection.
embedded_data¶
- The symbol name to extract.
Reads a symbol from the uWSGI binary image.
ValueError If symbol is unavailable.
extract¶
Extracts file contents.
farm_get_msg¶
Reads a mule farm message.
ValueError If not in a mule
farm_msg¶
- Farm name to send message to.
Sends a message to the given farm.
get_logvar¶
Return user-defined log variable contents.
green_schedule¶
Switches to another green thread.
Note
Alias for suspend.
i_am_the_lord¶
Returns flag indicating whether you are the lord of the given legion.
i_am_the_spooler¶
Returns flag indicating whether you are the Spooler.
in_farm¶
- Farm name.
Returns flag indicating whether you (mule) belong
to the given farm. Returns None is not in a mule.
is_a_reload¶
Returns flag indicating whether reloading mechanics is used.
is_connected¶
is_locked¶
- Lock number.
Checks for the given lock.
Note
Lock 0 is always available.
ValueError For Spooler or invalid lock number
listen_queue¶
- Socket number.
Returns listen queue (backlog size) of the given socket.
ValueError If socket is not found
lock¶
- Lock number.
Sets the given lock.
Note
Lock 0 is always available.
ValueError For Spooler or invalid lock number
log¶
Logs a message.
log_this_request¶
Instructs uWSGI to log current request data.
logsize¶
Returns current log size.
loop¶
Returns current event loop name or None if loop is not set.
lord_scroll¶
Returns a Lord scroll for the Legion.
masterpid¶
Return the process identifier (PID) of the uWSGI master process.
mem¶
Returns memory usage tuple of ints: (rss, vsz).
metric_dec¶
Decrements the specified metric key value by the specified value.
metric_div¶
Divides the specified metric key value by the specified value.
metric_get¶
Returns metric value by key.
metric_inc¶
Increments the specified metric key value by the specified value.
metric_mul¶
Multiplies the specified metric key value by the specified value.
metric_set¶
Sets metric value.
metric_set_max¶
Sets metric value if it is greater that the current one.
metric_set_min¶
Sets metric value if it is less that the current one.
micros¶
Returns uWSGI clock microseconds.
mule_get_msg¶
-
Whether to manage signals.
-
Whether to manage farms.
-
Seconds.
Block until a mule message is received and return it.
This can be called from multiple threads in the same programmed mule.
ValueError If not in a mule.
mule_id¶
Returns current mule ID. 0 if not a mule (e.g. worker).
mule_msg¶
- Mule ID, or farm name.
Sends a message to a mule(s)/farm.
ValueError If no mules, or mule ID or farm name is not recognized.
offload¶
Offloads a file.
Warning
Currently not implemented.
ValueError If unable to offload.
parsefile¶
ready¶
Returns flag indicating whether we are ready to handle requests.
ready_fd¶
Returns flag indicating whether file description related to request is ready.
recv¶
- Chunk size (bytes).
Reads data from the given file descriptor.
register_rpc¶
Registers RPC function.
ValueError If unable to register function
register_signal¶
-
Signal number.
-
workers- run the signal handler on all the workersworkerN- run the signal handler only on worker Nworker/worker0- run the signal handler on the first available worker-
active-workers- run the signal handlers on all the active [non-cheaped] workers -
mules- run the signal handler on all mules muleN- run the signal handler on mule N-
mule/mule0- run the signal handler on the first available mule -
spooler- run the signal on the first available spooler -
farmN/farm_XXX- run the signal handler in the mule farm N or named XXX -
http://uwsgi.readthedocs.io/en/latest/Signals.html#signals-targets
Registers a signal handler.
ValueError If unable to register
reload¶
Gracefully reloads uWSGI.
request_id¶
Returns current request number (handled by worker on core).
route¶
-
Route name
-
Comma-separated arguments string.
Registers a named route for internal routing subsystem.
rpc¶
- Function name to call.
Performs an RPC function call with the given arguments.
ValueError If unable to call RPC function.
rpc_list¶
Returns registered RPC functions names.
scrolls¶
Returns a list of Legion scrolls defined on cluster.
send¶
Puts data into file descriptor.
- One argument. Data to write into request file descriptor.
- Two arguments. 1. File descriptor; 2. Data to write.
send_to_spooler¶
-
The message to spool. Keys and values are bytes.
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Possible kwargs (these are also reserved `message` argument dictionary keys): * spooler: The spooler (id or directory) to use. Specify the ABSOLUTE path of the spooler that has to manage this task * priority: Number. The priority of the message. Larger - less important. .. warning:: This works only if you enable `order_tasks` option in `spooler.set_basic_params()`. This will be the subdirectory in the spooler directory in which the task will be placed, you can use that trick to give a good-enough prioritization to tasks. .. note:: This is for systems with few resources. For better approach use multiple spoolers. * at: Unix time at which the task must be executed. The task will not be run until the 'at' time is passed. * body: A binary body to add to the message, in addition to the message dictionary itself. Use this key for objects bigger than 64k, the blob will be appended to the serialized uwsgi packet and passed back t o the spooler function as the 'body' argument.
Send data to the The uWSGI Spooler. Also known as spool().
Warning
Either message argument should contain a dictionary
this message dictionary will be constructed from kwargs.
sendfile¶
-
File path or descriptor number.
-
Not used.
-
Filesize. If
0will be determined automatically.
Runs a sendfile.
set_logvar¶
Sets log variable.
set_spooler_frequency¶
Sets how often the spooler runs.
set_user_harakiri¶
- Seconds.
0disable timer.
Sets user level harakiri.
set_warning_message¶
Sets a warning. This will be reported by pingers.
setprocname¶
Sets current process name.
signal¶
-
Signal number.
-
Remote address.
Sends the signal to master or remote.
ValueError If remote rejected the signal.
IOError If unable to deliver to remote.
signal_received¶
Get the number of the last signal received.
Used in conjunction with signal_wait.
signal_registered¶
Verifies the given signal has been registered.
signal_wait¶
Waits for the given of any signal.
Block the process/thread/async core until a signal is received. Use signal_received to get the number of the signal received. If a registered handler handles a signal, signal_wait will be interrupted and the actual handler will handle the signal.
SystemError If something went wrong.
spooler_get_task¶
- The relative or absolute path to the task to read.
Returns a spooler task information.
spooler_jobs¶
Returns a list of spooler jobs (filenames in spooler directory).
spooler_pid¶
Returns first spooler process ID
spooler_pids¶
Returns a list of all spooler processes IDs.
stop¶
Stops uWSGI.
suspend¶
Suspends handling of current coroutine/green thread and passes control to the next async core.
total_requests¶
Returns the total number of requests managed so far by the pool of uWSGI workers.
unlock¶
- Lock number.
Unlocks the given lock.
Note
Lock 0 is always available.
ValueError For Spooler or invalid lock number
wait_fd_read¶
-
File descriptor number.
-
Timeout. Default: infinite.
Suspends handling of the current request until there is something to be read on file descriptor.
May be called several times before yielding/suspending to add more file descriptors to the set to be watched.
OSError If unable to read.
wait_fd_write¶
-
File descriptor number.
-
Timeout. Default: infinite.
Suspends handling of the current request until there is nothing more to be written on file descriptor.
May be called several times to add more file descriptors to the set to be watched.
OSError If unable to read.
websocket_handshake¶
-
Websocket security key to use.
-
Override
Sec-WebSocket-Origin. -
Override
Sec-WebSocket-Protocol.
Waits for websocket handshake.
IOError If unable to complete handshake.
websocket_recv¶
Receives data from websocket.
IOError If unable to receive a message.
websocket_recv_nb¶
Receives data from websocket (non-blocking variant).
IOError If unable to receive a message.
websocket_send¶
-
data to send
-
.. note:: uWSGI 2.1+
Sends a message to websocket.
IOError If unable to send a message.
websocket_send_binary¶
-
data to send
-
.. note:: uWSGI 2.1+
Sends binary message to websocket.
IOError If unable to send a message.
worker_id¶
Returns current worker ID. 0 if not a worker (e.g. mule).
workers¶
Gets statistics for all the workers for the current server.
Returns tuple of dicts.