Lines Matching +full:hook +full:- +full:run +full:- +full:in +full:- +full:context
1 :mod:`sys` --- System-specific parameters and functions
5 :synopsis: Access system-specific parameters and functions.
7 --------------
26 .. function:: addaudithook(hook)
28 Append the callable *hook* to the list of active auditing hooks for the
32 hook will be called in the order it was added with the event name and the
34 called first, followed by hooks added in the current interpreter.
36 .. audit-event:: sys.addaudithook "" sys.addaudithook
40 new hook will not be added and the exception suppressed. As a result,
41 callers cannot assume that their hook has been added unless they control
51 .. impl-detail::
55 true value. Otherwise, trace functions will skip the hook.
62 not). If the command was executed using the :option:`-c` command line option to
63 the interpreter, ``argv[0]`` is set to the string ``'-c'``. If no script name
73 ``[os.fsencode(arg) for arg in sys.argv]``.
87 This function will raise the first exception raised by any hook. In general,
97 See the :ref:`audit events table <audit-events>` for all events raised by
105 Set during Python startup, before ``site.py`` is run, to the same value as
106 :data:`exec_prefix`. If not running in a
107 :ref:`virtual environment <venv-def>`, the values will stay the same; if
108 ``site.py`` finds that a virtual environment is in use, the values of
119 Set during Python startup, before ``site.py`` is run, to the same value as
120 :data:`prefix`. If not running in a :ref:`virtual environment <venv-def>`, the values
121 will stay the same; if ``site.py`` finds that a virtual environment is in
133 big-endian (most-significant byte first) platforms, and ``'little'`` on
134 little-endian (least-significant byte first) platforms.
140 Python interpreter. (This information is not available in any other way ---
168 currently active in that thread at the time the function is called. Note that
169 functions in the :mod:`traceback` module can build the call stack given such a
174 long as they remain deadlocked. The frame returned for a non-deadlocked thread
180 .. audit-event:: sys._current_frames "" sys._current_frames
185 This hook function is called by built-in :func:`breakpoint`. By default,
192 (positional and/or keyword). The built-in ``breakpoint()`` function passes
198 returns immediately; i.e. it is a no-op. If the environment variable is
200 Otherwise this variable should name a function to run, using Python's
201 dotted-import nomenclature, e.g. ``package.subpackage.module.function``.
202 In this case, ``package.subpackage.module`` would be imported and the
203 resulting module must have a callable named ``function()``. This is run,
204 passing in ``*args`` and ``**kws``, and whatever ``function()`` returns,
205 ``sys.breakpointhook()`` returns to the built-in :func:`breakpoint`
219 Print low-level information to stderr about the state of CPython's memory
222 If Python is configured --with-pydebug, it also performs some expensive
227 .. impl-detail::
243 ``sys.stdout``, and saves *value* in ``builtins._``. If ``repr(value)`` is
249 entered in an interactive Python session. The display of these values can be
250 customized by assigning another one-argument function to ``sys.displayhook``.
252 Pseudo-code::
280 ``False`` depending on the :option:`-B` command line option and the
287 If this is set (not ``None``), Python will write bytecode-cache ``.pyc``
289 directory, rather than from ``__pycache__`` directories in the source code
290 tree. Any ``__pycache__`` directories in the source code tree will be ignored
292 :mod:`compileall` as a pre-build step, you must ensure you run it with the
297 This value is initially set based on the value of the :option:`-X`
298 ``pycache_prefix=PATH`` command-line option or the
299 :envvar:`PYTHONPYCACHEPREFIX` environment variable (command-line takes
311 instance, and a traceback object. In an interactive session this happens just
312 before control is returned to the prompt; in a Python program this happens just
313 before the program exits. The handling of such top-level exceptions can be
314 customized by assigning another three-argument function to ``sys.excepthook``.
316 .. audit-event:: sys.excepthook hook,type,value,traceback sys.excepthook
318 Raise an auditing event ``sys.excepthook`` with arguments ``hook``,
320 If no hook has been set, ``hook`` may be ``None``. If any hook raises
321 an exception derived from :class:`RuntimeError` the call to the hook will
322 be suppressed. Otherwise, the audit hook exception will be reported as
329 by :func:`threading.Thread.run`.
340 ``excepthook``, ``unraisablehook`` can be restored in case they happen to
367 a :ref:`traceback object <traceback-objects>` which encapsulates the call
373 A string giving the site-specific directory prefix where the platform-dependent
375 be set at build time with the ``--exec-prefix`` argument to the
377 :file:`pyconfig.h` header file) are installed in the directory
379 installed in :file:`{exec_prefix}/lib/python{X.Y}/lib-dynload`, where *X.Y*
384 If a :ref:`virtual environment <venv-def>` is in effect, this
385 value will be changed in ``site.py`` to point to the virtual environment.
409 in the range 0--127, and produce undefined results otherwise. Some systems
414 object is printed to :data:`stderr` and results in an exit code of 1. In
423 If an error occurs in the cleanup after the Python interpreter
425 in the standard streams), the exit status is changed to 120.
436 :const:`debug` :option:`-d`
437 :const:`inspect` :option:`-i`
438 :const:`interactive` :option:`-i`
439 :const:`isolated` :option:`-I`
440 :const:`optimize` :option:`-O` or :option:`-OO`
441 :const:`dont_write_bytecode` :option:`-B`
442 :const:`no_user_site` :option:`-s`
443 :const:`no_site` :option:`-S`
444 :const:`ignore_environment` :option:`-E`
445 :const:`verbose` :option:`-v`
446 :const:`bytes_warning` :option:`-b`
447 :const:`quiet` :option:`-q`
448 :const:`hash_randomization` :option:`-R`
449 :const:`dev_mode` :option:`-X` ``dev``
450 :const:`utf8_mode` :option:`-X` ``utf8``
451 …:const:`int_max_str_digits` :option:`-X int_max_str_digits <-X>` (:ref:`integer string conversio…
455 Added ``quiet`` attribute for the new :option:`-q` flag.
464 Added ``isolated`` attribute for :option:`-I` ``isolated`` flag.
467 Added ``dev_mode`` attribute for the new :option:`-X` ``dev`` flag
468 and ``utf8_mode`` attribute for the new :option:`-X` ``utf8`` flag.
478 representation. The values correspond to the various floating-point
479 constants defined in the standard header file :file:`float.h` for the 'C'
485 +---------------------+----------------+--------------------------------------------------+
490 +---------------------+----------------+--------------------------------------------------+
492 | | | faithfully represented in a float; see below |
493 +---------------------+----------------+--------------------------------------------------+
494 | :const:`mant_dig` | DBL_MANT_DIG | float precision: the number of base-``radix`` |
495 | | | digits in the significand of a float |
496 +---------------------+----------------+--------------------------------------------------+
498 +---------------------+----------------+--------------------------------------------------+
499 | :const:`max_exp` | DBL_MAX_EXP | maximum integer *e* such that ``radix**(e-1)`` is|
501 +---------------------+----------------+--------------------------------------------------+
502 | :const:`max_10_exp` | DBL_MAX_10_EXP | maximum integer *e* such that ``10**e`` is in the|
504 +---------------------+----------------+--------------------------------------------------+
506 +---------------------+----------------+--------------------------------------------------+
507 | :const:`min_exp` | DBL_MIN_EXP | minimum integer *e* such that ``radix**(e-1)`` is|
509 +---------------------+----------------+--------------------------------------------------+
512 +---------------------+----------------+--------------------------------------------------+
514 +---------------------+----------------+--------------------------------------------------+
521 +---------------------+----------------+--------------------------------------------------+
533 >>> format(float(s), '.15g') # convert to float and back -> same value
549 in Python 3.1 and later. Otherwise, ``float_repr_style`` has value
550 ``'legacy'`` and ``repr(x)`` behaves in the same way as it did in
598 found in the :mod:`os` module (``RTLD_xxx`` constants, e.g.
608 used for filenames in all cases, although representing filenames as bytes
613 This encoding is always ASCII-compatible.
618 * In the UTF-8 mode, the encoding is ``utf-8`` on any platform.
620 * On macOS, the encoding is ``'utf-8'``.
624 * On Windows, the encoding may be ``'utf-8'`` or ``'mbcs'``, depending
627 * On Android, the encoding is ``'utf-8'``.
629 * On VxWorks, the encoding is ``'utf-8'``.
639 Return 'utf-8' in the UTF-8 mode.
679 Return the size of an object in bytes. The object can be any type of
680 object. All built-in objects will return correct results, but this
681 does not have to hold true for third-party extensions as it is implementation
713 .. audit-event:: sys._getframe "" sys._getframe
715 .. impl-detail::
718 It is not guaranteed to exist in all implementations of Python.
738 .. impl-detail::
743 thus may not be available in all Python implementations.
753 *platform_version* a 3-tuple and all other values are
763 +---------------------------------------+---------------------------------+
767 +---------------------------------------+---------------------------------+
770 +---------------------------------------+---------------------------------+
773 +---------------------------------------+---------------------------------+
781 is being emulated for the process. It is intended for use in logging rather
827 :ref:`numeric-hash`.
829 +---------------------+--------------------------------------------------+
832 | :const:`width` | width in bits used for hash values |
833 +---------------------+--------------------------------------------------+
835 +---------------------+--------------------------------------------------+
837 +---------------------+--------------------------------------------------+
839 +---------------------+--------------------------------------------------+
842 +---------------------+--------------------------------------------------+
845 +---------------------+--------------------------------------------------+
847 +---------------------+--------------------------------------------------+
849 +---------------------+--------------------------------------------------+
861 with each version, including proper support for non-production releases. For
872 as the result of passing it to the built-in :func:`hex` function. The
874 human-friendly encoding of the same information.
883 required to exist in all Python implementations.
889 *version* is a named tuple, in the same format as
899 *hexversion* is the implementation version in hexadecimal format, like
902 *cache_tag* is the tag used by the import machinery in the filenames of
904 implementation's name and version, like ``'cpython-33'``. However, a
910 the Python implementation. These non-standard attributes must start with
912 :data:`sys.implementation` will not change during a run of the interpreter,
930 +----------------------------------------+-----------------------------------------------+
933 | :const:`bits_per_digit` | number of bits held in each digit. Python |
934 | | integers are stored internally in base |
936 +----------------------------------------+-----------------------------------------------+
937 | :const:`sizeof_digit` | size in bytes of the C type used to |
939 +----------------------------------------+-----------------------------------------------+
943 +----------------------------------------+-----------------------------------------------+
944 | :const:`str_digits_check_threshold` | minimum non-zero value for |
947 | | :option:`-X int_max_str_digits <-X>`. |
948 +----------------------------------------+-----------------------------------------------+
959 arguments) when the interpreter is launched in :ref:`interactive mode
960 <tut-interactive>`. This is done after the :envvar:`PYTHONSTARTUP` file is
961 read, so that you can set this hook there. The :mod:`site` module
962 :ref:`sets this <rlcompleter-config>`.
964 .. audit-event:: cpython.run_interactivehook hook sys.__interactivehook__
967 ``cpython.run_interactivehook`` with the hook object as the argument when
968 the hook is called on startup.
975 Enter *string* in the table of "interned" strings and return the interned string
976 -- which is *string* itself or a copy. Interning strings is useful to gain a
977 little performance on dictionary lookup -- if the keys in a dictionary are
980 names used in Python programs are automatically interned, and the dictionaries
1002 and engage in post-mortem debugging without having to re-execute the command
1004 post-mortem debugger; see :mod:`pdb` module for
1014 take. It's usually ``2**31 - 1`` on a 32-bit platform and ``2**63 - 1`` on a
1015 64-bit platform.
1021 i.e. ``1114111`` (``0x10FFFF`` in hexadecimal).
1026 whether Unicode characters were stored as UCS-2 or UCS-4.
1036 imported is contained in a package, then the parent package's :attr:`__path__`
1037 attribute is passed in as a second argument. The method returns a
1052 :term:`Module specs <module spec>` were introduced in Python 3.4, by
1071 the environment variable :envvar:`PYTHONPATH`, plus an installation-dependent
1078 ``path[0]`` is the empty string, which directs Python to search modules in the
1098 Originally specified in :pep:`302`.
1109 Originally specified in :pep:`302`.
1119 platform-specific components to :data:`sys.path`, for instance.
1122 returned by ``uname -s`` with the first part of the version as returned by
1123 ``uname -r`` appended, e.g. ``'sunos5'`` or ``'freebsd8'``, *at the time
1128 # FreeBSD-specific code here...
1130 # Linux-specific code here...
1132 # AIX-specific code here...
1161 system-dependent version information.
1169 A string giving the site-specific directory prefix where the platform
1171 ``'/usr/local'``. This can be set at build time with the ``--prefix``
1173 library modules is installed in the directory :file:`{prefix}/lib/python{X.Y}`
1175 stored in :file:`{prefix}/include/python{X.Y}`, where *X.Y* is the version
1178 .. note:: If a :ref:`virtual environment <venv-def>` is in effect, this
1179 value will be changed in ``site.py`` to point to the virtual
1194 are only defined if the interpreter is in interactive mode. Their initial
1195 values in this case are ``'>>> '`` and ``'... '``. If a non-string object is
1196 assigned to either variable, its :func:`str` is re-evaluated each time the
1223 can be found in the :mod:`os` module (``RTLD_xxx`` constants, e.g.
1243 code profiler in Python. See chapter :ref:`profile` for more information on the
1248 thread-specific, but there is no way for the profiler to know about context switches between
1249 threads, so it does not make sense to use this in the presence of multiple threads. Also,
1250 its return value is not used, so it can simply return ``None``. Error in the profile
1258 .. audit-event:: sys.setprofile "" sys.setprofile
1273 a built-in. *arg* is the C function object.
1287 The highest possible limit is platform-dependent. A user may need to set the
1289 that supports a higher limit. This should be done with care, because a too-high
1302 Set the interpreter's thread switch interval (in seconds). This floating-point
1305 can be higher, especially if long-running internal functions or methods
1320 source code debugger in Python. The function is thread-specific; for a
1335 function for further tracing in that scope), or ``None`` to turn off tracing
1336 in that scope.
1338 If there is any error occurred in the trace function, it will be unset, just
1349 The interpreter is about to execute a new line of code or re-execute the
1354 Per-line events may be disabled for a frame by setting
1372 Per-opcode events are not emitted by default: they must be explicitly
1379 For more fine-grained usage, it's possible to set a trace function by
1383 the current frame, which :func:`settrace` doesn't do. Note that in order
1385 with :func:`settrace` in order to enable the runtime tracing machinery,
1392 .. audit-event:: sys.settrace "" sys.settrace
1394 .. impl-detail::
1399 thus may not be available in all Python implementations.
1414 .. audit-event:: sys.set_asyncgen_hooks_firstiter "" sys.set_asyncgen_hooks
1416 .. audit-event:: sys.set_asyncgen_hooks_finalizer "" sys.set_asyncgen_hooks
1424 ``asyncio.Loop.shutdown_asyncgens`` in
1444 This setting is thread-specific.
1482 * The character encoding is platform-dependent. Non-Windows
1486 On Windows, UTF-8 is used for the console device. Non-character
1488 encoding (i.e. the ANSI codepage). Non-console character
1497 before starting Python. In that case, the console codepages are
1502 starting Python or by using the new :option:`-X` ``utf8`` command
1507 * When interactive, ``stdout`` and ``stderr`` streams are line-buffered.
1508 Otherwise, they are block-buffered like regular text files. You can
1509 override this value with the :option:`-u` command-line option.
1517 However, if you are writing a library (and do not control in which
1518 context its code will be executed), be aware that the standard streams
1519 may be replaced with file-like objects like :class:`io.StringIO` which
1533 in case they have been overwritten with a broken object. However, the
1551 +------------------+---------------------------------------------------------+
1559 +------------------+---------------------------------------------------------+
1566 +------------------+---------------------------------------------------------+
1569 +------------------+---------------------------------------------------------+
1598 The default hook formats *err_msg* and *object* as:
1599 ``f'{err_msg}: {object!r}'``; use "Exception ignored in" error message
1605 Storing *exc_value* using a custom hook can create a reference cycle. It
1609 Storing *object* using a custom hook can resurrect it if it is set to an
1611 hook completes to avoid resurrecting objects.
1615 .. audit-event:: sys.unraisablehook hook,unraisable sys.unraisablehook
1618 ``hook``, ``unraisable`` when an exception that cannot be handled occurs.
1619 The ``unraisable`` object is the same as what will be passed to the hook.
1620 If no hook has been set, ``hook`` may be ``None``.
1662 stored as string resource 1000 in the Python DLL. The value is normally the
1663 first three characters of :const:`version`. It is provided in the :mod:`sys`
1672 A dictionary of the various implementation-specific flags passed through
1673 the :option:`-X` command-line option. Option names are either mapped to
1676 .. code-block:: shell-session
1678 $ ./python -Xa=b -Xc
1686 .. impl-detail::
1688 This is a CPython-specific way of accessing options passed through
1689 :option:`-X`. Other implementations may export them through other
1697 …/IEC 9899:1999. "Programming languages -- C." A public draft of this standard is available at ht…