History log of /unit/src/python/nxt_python.c (Results 1 – 16 of 16)
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 2300:dc815c3c2244 05-Jan-2023 Andrew Clayton

Python: Fix enabling of UTF-8 in some situations.

There was a couple of reports of Python applications failing due to the
following type of error

File "/opt/netbox/netbox/netbox/configuration.py",

Python: Fix enabling of UTF-8 in some situations.

There was a couple of reports of Python applications failing due to the
following type of error

File "/opt/netbox/netbox/netbox/configuration.py", line 25, in _import
print(f"\U0001f9ec loaded config '{path}'")
UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f9ec' in
position 0: ordinal not in range(128)

due to the use of Unicode text in the print() statement.

This only happened for python 3.8+ when using the "home" configuration
option as this meant we were going through the new PyConfig
configuration.

When using this new configuration method with the 'isolated' specific
API (for embedded Python) UTF-8 is disabled by default,
PyPreConfig->utf8_mode = 0.

To fix this we need to setup the Python pre config and enable utf-8
mode. However rather than enable utf-8 unconditionally we can set to it
to -1 so that it will use the LC_CTYPE environment variable to determine
whether to enable utf-8 mode or not. utf-8 mode will be enabled if
LC_CTYPE is either: C, POSIX or some specific UTF-8 locale. This is the
default utf8_mode setting when using the non-isolated PyPreConfig API.

Reported-by: Tobias Genannt <tobias.genannt@kappa-velorum.net>
Tested-by: Tobias Genannt <tobias.genannt@kappa-velorum.net>
Link: <https://peps.python.org/pep-0587/>
Link: <https://docs.python.org/3/c-api/init_config.html#c.PyPreConfig.utf8_mode>
Fixes: 491d0f70 ("Python: Added support for Python 3.11.")
Closes: <https://github.com/nginx/unit/issues/817>
Reviewed-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>

show more ...


# 2299:913f17ec2663 30-Dec-2022 Andrew Clayton

Python: Do some cleanup in nxt_python3_init_config().

This is a preparatory patch for future work and cleans up the code a
little in the Python 3.8+ variant of nxt_python3_init_config().

The main a

Python: Do some cleanup in nxt_python3_init_config().

This is a preparatory patch for future work and cleans up the code a
little in the Python 3.8+ variant of nxt_python3_init_config().

The main advantage being we no longer have calls to PyConfig_Clear() in
two different paths.

The variables have a little extra space in their declarations to allow
for the next patch which introduces a variable with a longer type name,
which will help reduce the size of the diff.

Reviewed-by: Alejandro Colomar <alx@nginx.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>

show more ...


Revision tags: 1.29.0-1, 1.29.0
# 2273:a13c26f62477 14-Nov-2021 OutOfFocus4

Python: Added "prefix" to configuration.

This patch gives users the option to set a `"prefix"` attribute
for Python applications, either at the top level or for specific
`"target"`s. If the attribut

Python: Added "prefix" to configuration.

This patch gives users the option to set a `"prefix"` attribute
for Python applications, either at the top level or for specific
`"target"`s. If the attribute is present, the value of `"prefix"`
must be a string beginning with `"/"`. If the value of the `"prefix"`
attribute is longer than 1 character and ends in `"/"`, the
trailing `"/"` is stripped.

The purpose of the `"prefix"` attribute is to set the `SCRIPT_NAME`
context value for WSGI applications and the `root_path` context
value for ASGI applications, allowing applications to properly route
requests regardless of the path that the server uses to expose the
application.

The context value is only set if the request's URL path begins with
the value of the `"prefix"` attribute. In all other cases, the
`SCRIPT_NAME` or `root_path` values are not set. In addition, for
WSGI applications, the value of `"prefix"` will be stripped from
the beginning of the request's URL path before it is sent to the
application.

Reviewed-by: Andrei Zeliankou <zelenkov@nginx.com>
Reviewed-by: Artem Konev <artem.konev@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>

show more ...


# 2251:6e5a9550ead3 17-Nov-2022 Andrew Clayton

Python: Added support for Python 3.11.

Python 3.8 added a new Python initialisation configuration API[0].

Python 3.11 marked the old API as deprecated resulting in the following
compiler warnings w

Python: Added support for Python 3.11.

Python 3.8 added a new Python initialisation configuration API[0].

Python 3.11 marked the old API as deprecated resulting in the following
compiler warnings which we treat as errors, failing the build

src/python/nxt_python.c: In function ‘nxt_python_start’:
src/python/nxt_python.c:130:13: error: ‘Py_SetProgramName’ is deprecated [-Werror=deprecated-declarations]
130 | Py_SetProgramName(nxt_py_home);
| ^~~~~~~~~~~~~~~~~
In file included from /opt/python-3.11/include/python3.11/Python.h:94,
from src/python/nxt_python.c:7:
/opt/python-3.11/include/python3.11/pylifecycle.h:37:38: note: declared here
37 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *);
| ^~~~~~~~~~~~~~~~~
src/python/nxt_python.c:134:13: error: ‘Py_SetPythonHome’ is deprecated [-Werror=deprecated-declarations]
134 | Py_SetPythonHome(nxt_py_home);
| ^~~~~~~~~~~~~~~~
/opt/python-3.11/include/python3.11/pylifecycle.h:40:38: note: declared here
40 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *);
| ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

We actually have a few config scenarios: Python < 3, Python >= 3.0 < 3.8
and for Python 3 we have two configs where we select one based on
virtual environment setup.

Factor out the Python 3 config initialisation into its own function. We
actually create two functions, one for Python 3.8+ and one for older
Python 3. We pick the right function to use at build time.

The new API also has error checking (where the old API doesn't) which we
handle.

[0]: https://peps.python.org/pep-0587/

Closes: <https://github.com/nginx/unit/issues/710>
[ Andrew: Expanded upon patch from @sandeep-gh ]
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>

show more ...


# 2240:0c49318572c2 13-Sep-2022 OutOfFocus4

Removed dead code.

Signed-off-by: Alejandro Colomar <alx@nginx.com>


Revision tags: 1.28.0-1, 1.28.0, 1.27.0-1, 1.27.0
# 2077:624e51cfe97a 18-Dec-2021 Alejandro Colomar

Removed special cases for non-NXT_CONF_VALUE_ARRAY.

The previous commit added more generic APIs for handling
NXT_CONF_VALUE_ARRAY and non-NXT_CONF_VALUE_ARRAY together.
Modify calling code to remove

Removed special cases for non-NXT_CONF_VALUE_ARRAY.

The previous commit added more generic APIs for handling
NXT_CONF_VALUE_ARRAY and non-NXT_CONF_VALUE_ARRAY together.
Modify calling code to remove special cases for arrays and
non-arrays, taking special care that the path for non arrays is
logically equivalent to the previous special cased code.
Use the now-generic array code only.

show more ...


Revision tags: 1.26.1-1, 1.26.1, 1.26.0-1, 1.26.0
# 1980:43553aa72111 28-Oct-2021 Max Romanov

Moving request limit control to libunit.

Introducting application graceful stop. For now only used when application
process reach request limit value.

This closes #585 issue on GitHub.


Revision tags: 1.25.0-1, 1.25.0
# 1932:ee35fc1dca33 09-Aug-2021 Max Romanov

Python: fixing misprint in error message.


# 1918:b15674b9a39a 20-Jul-2021 Max Romanov

Python: using default event_loop for main thread for ASGI.

Unit's ASGI implementation creates a new event loop to run an application for
each thread since 542b5b8c0647. This may cause unexpected ex

Python: using default event_loop for main thread for ASGI.

Unit's ASGI implementation creates a new event loop to run an application for
each thread since 542b5b8c0647. This may cause unexpected exceptions or
strange bugs if asyncio synchronisation primitives are initialised before the
application starts (e.g. globally).

Although the approach with a new event loop for the main thread is consistent
and helps to prepare the application to run in multiple threads, it can be a
source of pain for people who just want to run single-threaded ASGI
applications in Unit.

This is related to #560 issue on GitHub.

show more ...


Revision tags: 1.24.0-1, 1.24.0
# 1872:9f8df8b810e0 20-May-2021 Oisin Canty

Python: support for multiple targets.


Revision tags: 1.23.0-1, 1.23.0, 1.22.0-1, 1.22.0
# 1759:196b4d90c8cc 22-Dec-2020 Valentin Bartenev

Python: multiple values in the "path" option.


Revision tags: 1.21.0-1, 1.21.0
# 1697:73a335d2911d 10-Nov-2020 Max Romanov

Python: supporting ASGI legacy protocol.

Introducing manual protocol selection for 'universal' apps and frameworks.


# 1681:542b5b8c0647 04-Nov-2020 Max Romanov

Python: request processing in multiple threads.

This closes #459 issue on GitHub.


Revision tags: 1.20.0-1, 1.20.0
# 1624:e46b1b422545 01-Oct-2020 Max Romanov

Python: ASGI server introduced.

This closes #461 issue on GitHub.


# 1601:365bbeccef1c 18-Sep-2020 Max Romanov

Python: app module callable name configuration.

Now it is possible to specify the name of the application callable using
optional parameter 'callable'. Default value is 'application'.

This closes

Python: app module callable name configuration.

Now it is possible to specify the name of the application callable using
optional parameter 'callable'. Default value is 'application'.

This closes #290 issue on GitHub.

show more ...


# 1592:9727c9b61f1c 14-Sep-2020 Max Romanov

Python: split module initialization from WSGI implementation.

This is required for futher ASGI implementation.