signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
def metric_set_max(key, value): | Sets metric value if it is greater that the current one.
:param str|unicode key:
:param int|long value:
:rtype: bool | f13072:m58 | |
def metric_set_min(key, value): | Sets metric value if it is less that the current one.
:param str|unicode key:
:param int|long value:
:rtype: bool | f13072:m59 | |
def micros(): | Returns uWSGI clock microseconds.
:rtype|long | f13072:m60 | |
def mule_get_msg(signals=None, farms=None, buffer_size=<NUM_LIT>, timeout=-<NUM_LIT:1>): | Block until a mule message is received and return it.
This can be called from multiple threads in the same programmed mule.
.. warning:: Bytes are returned for Python 3.
:param bool signals: Whether to manage signals.
:param bool farms: Whether to manage farms.
:param int buffer_size:
:param int timeout: Seconds.
:rtype: bytes|str
:raises ValueError: If not in a mule. | f13072:m61 | |
def mule_id(): | Returns current mule ID.
:rtype: int | f13072:m62 | |
def mule_msg(message, mule_farm=None): | Sends a message to a mule(s)/farm.
:param str|unicode message:
:param mule_farm: Mule ID, or farm name.
:rtype: bool
:raises ValueError: If no mules, or mule ID or farm name is not recognized. | f13072:m63 | |
def offload(filename): | Offloads a file.
.. warning:: Currently not implemented.
:param filename:
:rtype: bytes|str
:raises ValueError: If unable to offload. | f13072:m64 | |
def parsefile(fpath): | Parses the given file.
Currently implemented only Spooler file parsing.
:param str|unicode fpath:
:rtype: None | f13072:m65 | |
def ready(): | Returns flag indicating whether we are ready to handle requests.
:rtype: bool | f13072:m66 | |
def ready_fd(): | Returns flag indicating whether file description related to request is ready.
:rtype: bool | f13072:m67 | |
def recv(fd, maxsize=<NUM_LIT>): | Reads data from the given file descriptor.
.. warning:: Bytes are returned for Python 3.
:param int fd:
:param int maxsize: Chunk size (bytes).
:rtype: bytes|str | f13072:m68 | |
def register_rpc(name, func): | Registers RPC function.
* http://uwsgi.readthedocs.io/en/latest/RPC.html
:param str|unicode name:
:param callable func:
:rtype: bool
:raises ValueError: If unable to register function | f13072:m69 | |
def register_signal(number, target, func): | Registers a signal handler.
:param int number: Signal number.
:param str|unicode target:
* ``workers`` - run the signal handler on all the workers
* ``workerN`` - run the signal handler only on worker N
* ``worker/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 of the 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
:param callable func:
:rtype: None
:raises ValueError: If unable to register | f13072:m70 | |
def reload(): | Gracefully reloads uWSGI.
* http://uwsgi.readthedocs.io/en/latest/Management.html#reloading-the-server
:rtype: bool | f13072:m71 | |
def request_id(): | Returns current request number (handled by worker on core).
:rtype: int | f13072:m72 | |
def route(name, args_str): | Registers a named route for internal routing subsystem.
:param str name: Route name
:param args_str: Comma-separated arguments string.
:rtype: int | f13072:m73 | |
def rpc(address, func_name, *args): | Performs an RPC function call with the given arguments.
* http://uwsgi.readthedocs.io/en/latest/RPC.html
.. warning:: Bytes are returned for Python 3.
:param str|unicode address:
:param str|unicode func_name: Function name to call.
:param list[str|bytes] args:
:rtype: bytes|str
:raises ValueError: If unable to call RPC function. | f13072:m74 | |
def rpc_list(): | Returns registered RPC functions names.
:rtype: tuple | f13072:m75 | |
def scrolls(legion_name): | Returns a list of Legion scrolls defined on cluster.
:param str|unicode legion_name:
:rtype: list | f13072:m76 | |
def send(fd_or_data, data=None): | Puts data into file descriptor.
* One argument. Data to write into request file descriptor.
* Two arguments. 1. File descriptor; 2. Data to write.
:param df_or_data:
:param data:
:rtype: bool | f13072:m77 | |
def sendfile(fd_or_name, chunk_size=<NUM_LIT:0>, start_pos=<NUM_LIT:0>, filesize=<NUM_LIT:0>): | Runs a sendfile.
:param int|str|unicode fd_or_name: File path or descriptor number.
:param int chunk_size: Not used.
:param int start_pos:
:param int filesize: Filesize. If ``0`` will be determined automatically.
:rtype: bool|None | f13072:m78 | |
def set_logvar(name, value): | Sets log variable.
:param str|unicode name:
:param str|unicode value:
:rtype: None | f13072:m79 | |
def set_user_harakiri(timeout=<NUM_LIT:0>): | Sets user level harakiri.
:param int timeout: Seconds. ``0`` disable timer.
:rtype: None | f13072:m80 | |
def set_warning_message(message): | Sets a warning. This will be reported by pingers.
:param str|unicode message:
:rtype: bool | f13072:m81 | |
def setprocname(name): | Sets current process name.
:param str|unicode name:
:rtype: bool | f13072:m82 | |
def signal(num, remote='<STR_LIT>'): | Sends the signal to master or remote.
:param num: Signal number.
:param str|unicode remote: Remote address.
:rtype: None
:raises ValueError: If remote rejected the signal.
:raises IOError: If unable to deliver to remote. | f13072:m83 | |
def signal_received(): | Get the number of the last signal received.
Used in conjunction with ``signal_wait``.
* http://uwsgi-docs.readthedocs.io/en/latest/Signals.html#signal-wait-and-signal-received
:rtype: int | f13072:m84 | |
def signal_registered(num): | Verifies the given signal has been registered.
:param int num:
:rtype: bool|None | f13072:m85 | |
def signal_wait(num=None): | 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.
* http://uwsgi-docs.readthedocs.io/en/latest/Signals.html#signal-wait-and-signal-received
:param int num:
:rtype: str|unicode
:raises SystemError: If something went wrong. | f13072:m86 | |
def sockets(): | Returns a current list file descriptors for registered sockets.
:rtype: list[int] | f13072:m87 | |
def stop(): | Stops uWSGI.
:rtype: bool|None | f13072:m88 | |
def total_requests(): | Returns the total number of requests managed so far by the pool of uWSGI workers.
:rtype: int | f13072:m89 | |
def unlock(lock_num=<NUM_LIT:0>): | Unlocks the given lock.
.. note:: Lock 0 is always available.
:param int lock_num: Lock number.
:rtype: None
:raises ValueError: For Spooler or invalid lock number | f13072:m90 | |
def wait_fd_read(fd, timeout=None): | 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.
* http://uwsgi-docs.readthedocs.io/en/latest/Async.html#waiting-for-i-o
:param int fd: File descriptor number.
:param int timeout: Timeout. Default: infinite.
:rtype: bytes|str
:raises IOError: If unable to read. | f13072:m91 | |
def wait_fd_write(fd, timeout=None): | 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.
* http://uwsgi-docs.readthedocs.io/en/latest/Async.html#waiting-for-i-o
:param int fd: File descriptor number.
:param int timeout: Timeout. Default: infinite.
:rtype: bytes|str
:raises IOError: If unable to read. | f13072:m92 | |
def websocket_handshake(security_key=None, origin=None, proto=None): | Waits for websocket handshake.
:param str|unicode security_key: Websocket security key to use.
:param str|unicode origin: Override ``Sec-WebSocket-Origin``.
:param str|unicode proto: Override ``Sec-WebSocket-Protocol``.
:rtype: None
:raises IOError: If unable to complete handshake. | f13072:m93 | |
def websocket_recv(request_context=None): | Receives data from websocket.
:param request_context:
:rtype: bytes|str
:raises IOError: If unable to receive a message. | f13072:m94 | |
def websocket_recv_nb(request_context=None): | Receives data from websocket (non-blocking variant).
:param request_context:
:rtype: bytes|str
:raises IOError: If unable to receive a message. | f13072:m95 | |
def websocket_send(message, request_context=None): | Sends a message to websocket.
:param str message: data to send
:param request_context:
:raises IOError: If unable to send a message. | f13072:m96 | |
def websocket_send_binary(message, request_context=None): | Sends binary message to websocket.
:param str message: data to send
:param request_context:
:raises IOError: If unable to send a message. | f13072:m97 | |
def worker_id(): | Returns current worker ID.
:rtype: int | f13072:m98 | |
def workers(): | Gets statistics for all the workers for the current server.
Returns tuple of dicts.
:rtype: tuple[dict] | f13072:m99 | |
def get_tpl_systemd(conf): | tpl = '''<STR_LIT>'''<EOL>uid, gid = conf.main_process.get_owner()<EOL>tpl = tpl % {<EOL>'<STR_LIT>': conf.replace_placeholders('<STR_LIT>'),<EOL>'<STR_LIT:path>': UwsgiRunner.get_env_path(),<EOL>'<STR_LIT:user>': uid,<EOL>'<STR_LIT>': gid,<EOL>}<EOL>return tpl<EOL> | Some Systemd hints:
* uwsgiconf sysinit > my.service
* sudo cp my.service /etc/systemd/system/
* sudo sh -c "systemctl daemon-reload; systemctl start my.service"
* journalctl -fu my.service
:param Section conf: Section object.
:rtype: str|unicode | f13073:m0 |
def get_tpl_upstart(conf): | tpl = '''<STR_LIT>'''<EOL>uid, gid = conf.main_process.get_owner()<EOL>tpl = tpl % {<EOL>'<STR_LIT:path>': UwsgiRunner.get_env_path(),<EOL>'<STR_LIT>': conf.replace_placeholders('<STR_LIT>'),<EOL>'<STR_LIT:user>': uid,<EOL>'<STR_LIT>': gid,<EOL>}<EOL>return tpl<EOL> | :param Section conf: Section object.
:rtype: str|unicode | f13073:m1 |
def get_config(systype, conf, conf_path, runner=None, project_name=None): | runner = runner or ('<STR_LIT>' % Finder.uwsgiconf())<EOL>conf_path = abspath(conf_path)<EOL>if isinstance(conf, Configuration):<EOL><INDENT>conf = conf.sections[<NUM_LIT:0>] <EOL><DEDENT>tpl = dedent(TEMPLATES.get(systype)(conf=conf))<EOL>formatted = tpl.strip().format(<EOL>project=project_name or conf.project_name or basename(dirname(conf_path)),<EOL>command='<STR_LIT>' % (runner, conf_path),<EOL>)<EOL>return formatted<EOL> | Returns init system configuration file contents.
:param str|unicode systype: System type alias, e.g. systemd, upstart
:param Section|Configuration conf: Configuration/Section object.
:param str|unicode conf_path: File path to a configuration file or a command producing such a configuration.
:param str|unicode runner: Runner command to execute conf_path. Defaults to ``uwsgiconf`` runner.
:param str|unicode project_name: Project name to override.
:rtype: str|unicode | f13073:m2 |
def format_print_text(text, color_fg=None, color_bg=None): | from .config import Section<EOL>color_fg = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}.get(color_fg, '<STR_LIT>')<EOL>color_bg = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:100>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}.get(color_bg, '<STR_LIT>')<EOL>mod = '<STR_LIT:;>'.join([color_fg, color_bg])<EOL>text = '<STR_LIT>' % {<EOL>'<STR_LIT>': Section.vars.FORMAT_ESCAPE,<EOL>'<STR_LIT:end>': Section.vars.FORMAT_END,<EOL>'<STR_LIT>': mod,<EOL>'<STR_LIT:value>': text,<EOL>}<EOL>return text<EOL> | Format given text using ANSI formatting escape sequences.
Could be useful gfor print command.
:param str|unicode text:
:param str|unicode color_fg: text (foreground) color
:param str|unicode color_bg: text (background) color
:rtype: str|unicode | f13074:m0 |
def iter_options(self): | for section in self.sections:<EOL><INDENT>name = str(section)<EOL>for key, value in section._get_options():<EOL><INDENT>yield name, key, value<EOL><DEDENT><DEDENT> | Iterates configuration sections groups options. | f13074:c0:m1 |
def encode(value): | return value.encode('<STR_LIT:utf-8>') if PY3 and isinstance(value, str) else value<EOL> | Encodes str into bytes if required. | f13076:m1 |
def decode(value): | return value.decode('<STR_LIT:utf-8>') if PY3 and isinstance(value, bytes) else value<EOL> | Decodes bytes into str if required. | f13076:m2 |
@contextmanager<EOL>def output_capturing(): | out = sys.stdout<EOL>sys.stdout = StringIO()<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>sys.stdout = out<EOL><DEDENT> | Temporarily captures/redirects stdout. | f13076:m3 |
def listify(src): | if not isinstance(src, list):<EOL><INDENT>src = [src]<EOL><DEDENT>return src<EOL> | Make a list with source object if not already a list.
:param src:
:rtype: list | f13076:m4 |
def filter_locals(locals_dict, drop=None, include=None): | drop = drop or []<EOL>drop.extend([<EOL>'<STR_LIT>',<EOL>'<STR_LIT>', <EOL>])<EOL>include = include or locals_dict.keys()<EOL>relevant_keys = [key for key in include if key not in drop]<EOL>locals_dict = {k: v for k, v in locals_dict.items() if k in relevant_keys}<EOL>return locals_dict<EOL> | Filters a dictionary produced by locals().
:param dict locals_dict:
:param list drop: Keys to drop from dict.
:param list include: Keys to include into dict.
:rtype: dict | f13076:m5 |
def get_output(cmd, args): | from subprocess import Popen, STDOUT, PIPE<EOL>command = [cmd]<EOL>command.extend(listify(args))<EOL>process = Popen(command, stdout=PIPE, stderr=STDOUT)<EOL>out, _ = process.communicate()<EOL>return out.decode('<STR_LIT:utf-8>')<EOL> | Runs a command and returns its output (stdout + stderr).
:param str|unicode cmd:
:param str|unicode|list[str|unicode] args:
:rtype: str|unicode | f13076:m6 |
def parse_command_plugins_output(out): | out = out.split('<STR_LIT>')[<NUM_LIT:0>]<EOL>out = out.partition('<STR_LIT>')[<NUM_LIT:2>]<EOL>out = out.splitlines()<EOL>current_slot = <NUM_LIT:0><EOL>plugins = EmbeddedPlugins([], [])<EOL>for line in out:<EOL><INDENT>line = line.strip()<EOL>if not line:<EOL><INDENT>continue<EOL><DEDENT>if line.startswith('<STR_LIT>'):<EOL><INDENT>current_slot += <NUM_LIT:1><EOL>continue<EOL><DEDENT>if current_slot is not None:<EOL><INDENT>plugins[current_slot].append(line)<EOL><DEDENT><DEDENT>plugins = plugins._replace(request=[plugin.partition('<STR_LIT:U+0020>')[<NUM_LIT:2>] for plugin in plugins.request])<EOL>return plugins<EOL> | Parses ``plugin-list`` command output from uWSGI
and returns object containing lists of embedded plugin names.
:param str|unicode out:
:rtype EmbeddedPlugins: | f13076:m7 |
def get_uwsgi_stub_attrs_diff(): | try:<EOL><INDENT>import uwsgi<EOL><DEDENT>except ImportError:<EOL><INDENT>from uwsgiconf.exceptions import UwsgiconfException<EOL>raise UwsgiconfException(<EOL>'<STR_LIT>')<EOL><DEDENT>from . import uwsgi_stub<EOL>def get_attrs(src):<EOL><INDENT>return set(attr for attr in dir(src) if not attr.startswith('<STR_LIT:_>'))<EOL><DEDENT>attrs_uwsgi = get_attrs(uwsgi)<EOL>attrs_stub = get_attrs(uwsgi_stub)<EOL>from_uwsgi = sorted(attrs_uwsgi.difference(attrs_stub))<EOL>from_stub = sorted(attrs_stub.difference(attrs_uwsgi))<EOL>return from_uwsgi, from_stub<EOL> | Returns attributes difference two elements tuple between
real uwsgi module and its stub.
Might be of use while describing in stub new uwsgi functions.
:return: (uwsgi_only_attrs, stub_only_attrs)
:rtype: tuple | f13076:m8 |
def __init__(self, fpath): | fpath = os.path.abspath(fpath)<EOL>self.fpath = fpath<EOL>self._confs = None<EOL> | Module filepath.
:param fpath: | f13076:c0:m0 |
def spawn_uwsgi(self, only=None): | spawned = []<EOL>configs = self.configurations<EOL>if len(configs) == <NUM_LIT:1>:<EOL><INDENT>alias = configs[<NUM_LIT:0>].alias<EOL>UwsgiRunner().spawn(self.fpath, alias, replace=True)<EOL>spawned.append((alias, os.getpid()))<EOL><DEDENT>else:<EOL><INDENT>for config in configs: <EOL><INDENT>alias = config.alias<EOL>if only is None or alias == only:<EOL><INDENT>pid = UwsgiRunner().spawn(self.fpath, alias)<EOL>spawned.append((alias, pid))<EOL><DEDENT><DEDENT><DEDENT>return spawned<EOL> | Spawns uWSGI process(es) which will use configuration(s) from the module.
Returns list of tuples:
(configuration_alias, uwsgi_process_id)
If only one configuration found current process (uwsgiconf) is replaced with a new one (uWSGI),
otherwise a number of new detached processes is spawned.
:param str|unicode only: Configuration alias to run from the module.
If not set uWSGI will be spawned for every configuration found in the module.
:rtype: list | f13076:c0:m1 |
@property<EOL><INDENT>def configurations(self):<DEDENT> | if self._confs is not None:<EOL><INDENT>return self._confs<EOL><DEDENT>with output_capturing():<EOL><INDENT>module = self.load(self.fpath)<EOL>confs = getattr(module, CONFIGS_MODULE_ATTR)<EOL>confs = listify(confs)<EOL><DEDENT>self._confs = confs<EOL>return confs<EOL> | Configurations from uwsgiconf module. | f13076:c0:m2 |
@classmethod<EOL><INDENT>def load(cls, fpath):<DEDENT> | module_name = os.path.splitext(os.path.basename(fpath))[<NUM_LIT:0>]<EOL>sys.path.insert(<NUM_LIT:0>, os.path.dirname(fpath))<EOL>try:<EOL><INDENT>module = import_module(module_name)<EOL><DEDENT>finally:<EOL><INDENT>sys.path = sys.path[<NUM_LIT:1>:]<EOL><DEDENT>return module<EOL> | Loads a module and returns its object.
:param str|unicode fpath:
:rtype: module | f13076:c0:m3 |
def __init__(<EOL>self, locals_dict, keys=None, aliases=None, bool_keys=None, list_keys=None,<EOL>items_separator='<STR_LIT:U+002C>'): | self.locals_dict = dict(locals_dict)<EOL>self.keys = keys or sorted(filter_locals(locals_dict).keys())<EOL>self.aliases = aliases or {}<EOL>self.bool_keys = bool_keys or []<EOL>self.list_keys = list_keys or []<EOL>self.items_separator = items_separator<EOL> | :param dict locals_dict: Dictionary produced by locals().
:param list keys: Relevant keys from dictionary.
If not defined - all keys are relevant.
If defined keys will flattened into string using given order.
:param dict aliases: Mapping key names from locals_dict into names
they should be replaced with.
:param list bool_keys: Keys to consider their values bool.
:param list list_keys: Keys expecting lists.
:param str|unicode items_separator: String to use as items (chunks) separator.
:rtype: str|unicode | f13076:c1:m0 |
@classmethod<EOL><INDENT>def uwsgiconf(cls):<DEDENT> | return get_output('<STR_LIT>', ['<STR_LIT>']).strip()<EOL> | Finds uwsgiconf executable location.
:rtype: str|unicode | f13076:c2:m0 |
@classmethod<EOL><INDENT>def python(cls):<DEDENT> | return sys.executable<EOL> | Finds Python executable location.
:rtype: str|unicode | f13076:c2:m1 |
def __init__(self, fifo_filepath): | self.fifo = fifo_filepath<EOL> | :param str|unicode fifo_filepath: Path to uWSGI Master FIFO file. | f13076:c3:m0 |
def cmd_log(self, reopen=False, rotate=False): | cmd = b'<STR_LIT>'<EOL>if reopen:<EOL><INDENT>cmd += b'<STR_LIT:l>'<EOL><DEDENT>if rotate:<EOL><INDENT>cmd += b'<STR_LIT:L>'<EOL><DEDENT>return self.send_command(cmd)<EOL> | Allows managing of uWSGI log related stuff
:param bool reopen: Reopen log file. Could be required after third party rotation.
:param bool rotate: Trigger built-in log rotation. | f13076:c3:m1 |
def cmd_stats(self): | return self.send_command(b'<STR_LIT:s>')<EOL> | Dump uWSGI configuration and current stats into the log. | f13076:c3:m2 |
def cmd_stop(self, force=False): | return self.send_command(b'<STR_LIT>' if force else b'<STR_LIT:q>')<EOL> | Shutdown uWSGI instance.
:param bool force: Use forced (brutal) shutdown instead of a graceful one. | f13076:c3:m3 |
def cmd_reload(self, force=False, workers_only=False, workers_chain=False): | if workers_chain:<EOL><INDENT>return self.send_command(b'<STR_LIT:c>')<EOL><DEDENT>if workers_only:<EOL><INDENT>return self.send_command(b'<STR_LIT:R>' if force else b'<STR_LIT:r>')<EOL><DEDENT>return self.send_command(b'<STR_LIT:R>' if force else b'<STR_LIT:r>')<EOL> | Reloads uWSGI master process, workers.
:param bool force: Use forced (brutal) reload instead of a graceful one.
:param bool workers_only: Reload only workers.
:param bool workers_chain: Run chained workers reload (one after another,
instead of destroying all of them in bulk). | f13076:c3:m4 |
def send_command(self, cmd): | if not cmd:<EOL><INDENT>return<EOL><DEDENT>with open(self.fifo, '<STR_LIT:wb>') as f:<EOL><INDENT>f.write(cmd)<EOL><DEDENT> | Sends a generic command into FIFO.
:param bytes cmd: Command chars to send into FIFO. | f13076:c3:m5 |
def get_output(self, command_args): | return get_output(self.binary_uwsgi, command_args)<EOL> | Runs a command and returns its output (stdout + stderr).
:param str|unicode|list[str|unicode] command_args:
:rtype: str|unicode | f13076:c4:m1 |
def get_plugins(self): | out = self.get_output('<STR_LIT>')<EOL>return parse_command_plugins_output(out)<EOL> | Returns ``EmbeddedPlugins`` object with
:rtype EmbeddedPlugins: | f13076:c4:m2 |
@classmethod<EOL><INDENT>def get_env_path(cls):<DEDENT> | return os.path.dirname(Finder.python()) + os.pathsep + os.environ['<STR_LIT>']<EOL> | Returns PATH environment variable updated to run uwsgiconf in
(e.g. for virtualenv).
:rtype: str|unicode | f13076:c4:m3 |
@classmethod<EOL><INDENT>def prepare_env(cls):<DEDENT> | os.environ['<STR_LIT>'] = cls.get_env_path()<EOL>return os.path.basename(Finder.python())<EOL> | Prepares current environment and returns Python binary name.
This adds some virtualenv friendliness so that we try use uwsgi from it.
:rtype: str|unicode | f13076:c4:m4 |
def spawn(self, filepath, configuration_alias, replace=False): | <EOL>args = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>' % (self.binary_python, filepath, configuration_alias)]<EOL>if replace:<EOL><INDENT>return os.execvp('<STR_LIT>', args)<EOL><DEDENT>return os.spawnvp(os.P_NOWAIT, '<STR_LIT>', args)<EOL> | Spawns uWSGI using the given configuration module.
:param str|unicode filepath:
:param str|unicode configuration_alias:
:param bool replace: Whether a new process should replace current one. | f13076:c4:m5 |
def __init__(self, timeout): | self._timeout = timeout<EOL> | :param int timeout: Timeout (seconds) before harakiri. | f13078:c0:m0 |
def get_available_num(): | for signum in range(<NUM_LIT:0>, <NUM_LIT>):<EOL><INDENT>if not uwsgi.signal_registered(signum):<EOL><INDENT>return signum<EOL><DEDENT><DEDENT>raise UwsgiconfException('<STR_LIT>')<EOL> | Returns first available signal number.
:rtype: int
:raises UwsgiconfException: If no signal is available. | f13080:m0 |
def get_last_received(): | return Signal(uwsgi.signal_received())<EOL> | Get the last signal received.
:rtype: Signal | f13080:m1 |
def __init__(self, num=None): | self.num = num or get_available_num()<EOL> | :param int num: Signal number (0-256).
.. note:: If not set it will be chosen automatically. | f13080:c0:m0 |
def register_handler(self, target=None): | target = target or '<STR_LIT>'<EOL>sign_num = self.num<EOL>def wrapper(func):<EOL><INDENT>_LOG.debug("<STR_LIT>", func.__name__, sign_num)<EOL>uwsgi.register_signal(sign_num, target, func)<EOL>return func<EOL><DEDENT>return wrapper<EOL> | Decorator for a function to be used as a signal handler.
:param str|unicode target: Where this signal will be delivered to. Default: ``worker``.
* ``workers`` - run the signal handler on all the workers
* ``workerN`` - run the signal handler only on worker N
* ``worker``/``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 of the 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 | f13080:c0:m2 |
def send(self, remote='<STR_LIT>'): | uwsgi.signal(self.num, remote)<EOL> | Sends the signal to master or remote.
:param str|unicode remote: Remote address.
:rtype: None
:raises ValueError: If remote rejected the signal.
:raises IOError: If unable to deliver to remote. | f13080:c0:m3 |
def wait(self): | uwsgi.signal_wait(self.num)<EOL> | 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.
* http://uwsgi-docs.readthedocs.io/en/latest/Signals.html#signal-wait-and-signal-received
:raises SystemError: If something went wrong. | f13080:c0:m4 |
def register_rpc(name=None): | def wrapper(func):<EOL><INDENT>func_name = func.__name__<EOL>rpc_name = name or func_name<EOL>uwsgi.register_rpc(rpc_name, func)<EOL>_LOG.debug("<STR_LIT>", func_name, rpc_name)<EOL>return func<EOL><DEDENT>return wrapper<EOL> | Decorator. Allows registering a function for RPC.
* http://uwsgi.readthedocs.io/en/latest/RPC.html
Example:
.. code-block:: python
@register_rpc()
def expose_me():
do()
:param str|unicode name: RPC function name to associate
with decorated function.
:rtype: callable | f13081:m0 |
def make_rpc_call(func_name, args=None, remote=None): | args = args or []<EOL>args = [encode(str(arg)) for arg in args]<EOL>if remote:<EOL><INDENT>result = uwsgi.rpc(remote, func_name, *args)<EOL><DEDENT>else:<EOL><INDENT>result = uwsgi.call(func_name, *args)<EOL><DEDENT>return decode(result)<EOL> | Performs an RPC function call (local or remote) with the given arguments.
:param str|unicode func_name: RPC function name to call.
:param Iterable args: Function arguments.
:param str|unicode remote:
:rtype: bytes|str
:raises ValueError: If unable to call RPC function. | f13081:m1 |
def get_rpc_list(): | return uwsgi.rpc_list()<EOL> | Returns registered RPC functions names.
:rtype: tuple | f13081:m2 |
@property<EOL><INDENT>def env(self):<DEDENT> | return uwsgi.env<EOL> | Request environment dictionary. | f13082:c0:m0 |
@property<EOL><INDENT>def id(self):<DEDENT> | return uwsgi.request_id()<EOL> | Returns current request number (handled by worker on core).
:rtype: int | f13082:c0:m1 |
@property<EOL><INDENT>def total_count(self):<DEDENT> | return uwsgi.total_requests()<EOL> | Returns the total number of requests managed so far by the pool of uWSGI workers.
:rtype: int | f13082:c0:m2 |
@property<EOL><INDENT>def fd(self):<DEDENT> | return uwsgi.connection_fd()<EOL> | Returns current request file descriptor.
:rtype: int | f13082:c0:m3 |
@property<EOL><INDENT>def content_length(self):<DEDENT> | return uwsgi.cl()<EOL> | Returns current post content length.
:rtype: int|long | f13082:c0:m4 |
def log(self): | uwsgi.log_this_request()<EOL> | Instructs uWSGI to log current request data.
:rtype: None | f13082:c0:m5 |
def add_var(self, name, value): | return uwsgi.add_var(name, value)<EOL> | Registers custom request variable.
Can be used for better integration with the internal routing subsystem.
:param str|unicode name:
:param str|unicode value:
:rtype: bool
:raises ValueError: If buffer size is not enough. | f13082:c0:m6 |
def register_timer(period, target=None): | return _automate_signal(target, func=lambda sig: uwsgi.add_timer(int(sig), period))<EOL> | Add timer.
Can be used as a decorator:
.. code-block:: python
@register_timer(3)
def repeat():
do()
:param int period: The interval (seconds) at which to raise the signal.
:param int|Signal|str|unicode target: Existing signal to raise
or Signal Target to register signal implicitly.
Available targets:
* ``workers`` - run the signal handler on all the workers
* ``workerN`` - run the signal handler only on worker N
* ``worker``/``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 of the 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
:rtype: bool|callable
:raises ValueError: If unable to add timer. | f13084:m0 |
def register_timer_rb(period, repeat=None, target=None): | return _automate_signal(target, func=lambda sig: uwsgi.add_rb_timer(int(sig), period, repeat or <NUM_LIT:0>))<EOL> | Add a red-black timer (based on black-red tree).
.. code-block:: python
@register_timer_rb(3)
def repeat():
do()
:param int period: The interval (seconds) at which the signal is raised.
:param int repeat: How many times to repeat. Default: None - infinitely.
:param int|Signal|str|unicode target: Existing signal to raise
or Signal Target to register signal implicitly.
Available targets:
* ``workers`` - run the signal handler on all the workers
* ``workerN`` - run the signal handler only on worker N
* ``worker``/``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 of the 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
:rtype: bool|callable
:raises ValueError: If unable to add timer. | f13084:m1 |
def register_cron(weekday=None, month=None, day=None, hour=None, minute=None, target=None): | task_args_initial = {name: val for name, val in locals().items() if val is not None and name != '<STR_LIT:target>'}<EOL>task_args_casted = {}<EOL>def skip_task(check_funcs):<EOL><INDENT>now = datetime.now()<EOL>allright = all((func(now) for func in check_funcs))<EOL>return not allright<EOL><DEDENT>def check_date(now, attr, target_range):<EOL><INDENT>attr = getattr(now, attr)<EOL>if callable(attr): <EOL><INDENT>attr = attr()<EOL><DEDENT>return attr in target_range<EOL><DEDENT>check_date_funcs = []<EOL>for name, val in task_args_initial.items():<EOL><INDENT>if isinstance(val, string_types):<EOL><INDENT>val, _, step = val.partition('<STR_LIT:/>')<EOL>step = int(step) if step else <NUM_LIT:1><EOL>start, _, end = val.partition('<STR_LIT:->')<EOL>if not (start and end):<EOL><INDENT>raise RuntimeConfigurationError(<EOL>'<STR_LIT>')<EOL><DEDENT>start = int(start)<EOL>end = int(end)<EOL>now_attr_name = name<EOL>period_range = set(range(start, end+<NUM_LIT:1>, step))<EOL>if name == '<STR_LIT>':<EOL><INDENT>now_attr_name = '<STR_LIT>'<EOL>if <NUM_LIT:0> in period_range:<EOL><INDENT>period_range.discard(<NUM_LIT:0>)<EOL>period_range.add(<NUM_LIT:7>)<EOL><DEDENT><DEDENT>check_date_funcs.append(partial(check_date, attr=now_attr_name, target_range=period_range))<EOL>val = None<EOL><DEDENT>task_args_casted[name] = val<EOL><DEDENT>if not check_date_funcs:<EOL><INDENT>args = [(-<NUM_LIT:1> if arg is None else arg) for arg in (minute, hour, day, month, weekday)]<EOL>return _automate_signal(target, func=lambda sig: uwsgi.add_cron(int(sig), *args))<EOL><DEDENT>skip_task = partial(skip_task, check_date_funcs)<EOL>def decor(func_action):<EOL><INDENT>"""<STR_LIT>"""<EOL>@wraps(func_action)<EOL>def func_action_wrapper(*args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>if skip_task():<EOL><INDENT>return None<EOL><DEDENT>return func_action(*args, **kwargs)<EOL><DEDENT>args = []<EOL>for arg_name in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>arg = task_args_casted.get(arg_name, None)<EOL>args.append(-<NUM_LIT:1> if arg is None else arg)<EOL><DEDENT>return _automate_signal(target, func=lambda sig: uwsgi.add_cron(int(sig), *args))(func_action_wrapper)<EOL><DEDENT>return decor<EOL> | Adds cron. The interface to the uWSGI signal cron facility.
.. code-block:: python
@register_cron(hour=-3) # Every 3 hours.
def repeat():
do()
.. note:: Arguments work similarly to a standard crontab,
but instead of "*", use -1,
and instead of "/2", "/3", etc. use -2 and -3, etc.
.. note:: Periods - rules like hour='10-18/2' (from 10 till 18 every 2 hours) - are allowed,
but they are emulated by uwsgiconf. Use strings to define periods.
Keep in mind, that your actual function will be wrapped into another one, which will check
whether it is time to call your function.
:param int|str|unicode weekday: Day of a the week number. Defaults to `each`.
0 - Sunday 1 - Monday 2 - Tuesday 3 - Wednesday
4 - Thursday 5 - Friday 6 - Saturday
:param int|str|unicode month: Month number 1-12. Defaults to `each`.
:param int|str|unicode day: Day of the month number 1-31. Defaults to `each`.
:param int|str|unicode hour: Hour 0-23. Defaults to `each`.
:param int|str|unicode minute: Minute 0-59. Defaults to `each`.
:param int|Signal|str|unicode target: Existing signal to raise
or Signal Target to register signal implicitly.
Available targets:
* ``workers`` - run the signal handler on all the workers
* ``workerN`` - run the signal handler only on worker N
* ``worker``/``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 of the 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
:rtype: bool|callable
:raises ValueError: If unable to add cron rule. | f13084:m2 |
def __init__(self, num=<NUM_LIT:0>): | self.num = num<EOL> | :param int num: Lock number (0-64). 0 is always available and is used as default. | f13086:c0:m0 |
@property<EOL><INDENT>def is_set(self):<DEDENT> | return uwsgi.is_locked(self.num)<EOL> | Checks whether the lock is active.
:rtype: bool
:raises ValueError: For Spooler or invalid lock number | f13086:c0:m4 |
def acquire(self): | uwsgi.lock(self.num)<EOL>return True<EOL> | Sets the lock.
:rtype: None
:raises ValueError: For Spooler or invalid lock number | f13086:c0:m5 |
def release(self): | uwsgi.unlock(self.num)<EOL>return True<EOL> | Unlocks the lock.
:rtype: None
:raises ValueError: For Spooler or invalid lock number | f13086:c0:m6 |
def register_file_monitor(filename, target=None): | return _automate_signal(target, func=lambda sig: uwsgi.add_file_monitor(int(sig), filename))<EOL> | Maps a specific file/directory modification event to a signal.
:param str|unicode filename: File or a directory to watch for its modification.
:param int|Signal|str|unicode target: Existing signal to raise
or Signal Target to register signal implicitly.
Available targets:
* ``workers`` - run the signal handler on all the workers
* ``workerN`` - run the signal handler only on worker N
* ``worker``/``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 of the 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
:raises ValueError: If unable to register monitor. | f13087:m0 |
def __init__(self, name): | self.name = name<EOL> | :param str|unicode name: Metric name. | f13087:c0:m0 |
@property<EOL><INDENT>def value(self):<DEDENT> | return uwsgi.metric_get(self.name)<EOL> | Current metric value.
:rtype: int|long | f13087:c0:m1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.