Skip to main content

Hi all.

I'm using the inspect module to extract information about our code. The code runs well in the Python console but when called from Universe Basic I'm getting a Python runtime error.

The Python side is really simple. I've reduced my code to a minimal example that reproduces it:

File: leer_documentacion_min.py

This is the module that does the inspection

import inspect
import json
import sys


def parameter_as_string(name, p):
    def_value = f' = {p.default}' if (not type(p.default) == type(inspect._empty)) else ''
    typ_annot = f':{p.annotation.__name__}' if (p.annotation.__name__ != '_empty') else ''
    return f'{name}{typ_annot}{def_value}'


def leer_documentacion_y_funciones(script):
    try:
        if script in sys.modules:
            sys.modules.pop(script)
        modulo = __import__(script)
        # rest of the code
        documentacion = modulo.__doc__ if modulo.__doc__ else 'Sin documentacion.'
        funciones = inspect.getmembers(modulo, inspect.isfunction)
        informacion_funciones = []
        for nombre, funcion_py in funciones:
            argumentos = inspect.signature(funcion_py).parameters
            lista_args = [parameter_as_string(p, argumentos[p]) for p in argumentos]
            informacion_funciones.append({'nombre': nombre, 'argumentos': '|'.join(lista_args)})

        sys.modules.pop(script)
        return json.dumps({
            'documentacion': documentacion,
            'numero_de_funciones': len(funciones),
            'informacion_funciones': informacion_funciones
        })
    except Exception as e:
        print(inspect.stack())
        import traceback
        traceback.print_exc()
        return f'KO - {e}'

File: lanza_metodo_min.py

This code is -mostly- irrelevant, as the part that reproduces the error is the first import.

import requests
import json


def lanza_metodo(client_id: str, client_secret: str, code: str, api: str, version: int, tipo_http: str, metodo: str):
    salida = False
    try:
        response_get = requests.get('https://community.rocketsoftware.com/home')
        salida = req.status_code == requests.codes.ok
    except Exception as err:
        print('Se ha producido un error general en la peticion ' + tipo_http + ' /' + metodo + ': ' + str(err))
    return salida

Now I write a simple BASIC UP:

RESPUESTA=PyCallFunction('leer_documentacion_min','leer_documentacion_y_funciones','lanza_metodo_min')
CRT 'Respuesta 1: ':RESPUESTA

When I run the code from the Python terminal it works fine, as expected:

SH-4.4$ /uv/python/bin/python3
Python 3.11.0 (main, Nov 16 2022, 04:47:09) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import leer_documentacion_min
>>> leer_documentacion_min.leer_documentacion_y_funciones('lanza_metodo_min')
'{"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}'
>>> leer_documentacion_min.leer_documentacion_y_funciones('lanza_metodo_min')
'{"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}'
>>> leer_documentacion_min.leer_documentacion_y_funciones('lanza_metodo_min')
'{"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}'
>>>

But when I run the BASIC UP from the TCL it starts to throw exceptions after the first call:

>RUN UP HCH_CRL
Respuesta 1: {"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}
>.X
01 RUN UP HCH_CRL
[FrameInfo(frame=<frame at 0x7f3518462440, file '/u2/quiter/GEN4GL/PYPROGS/leer_documentacion_min.py', line 36, code leer_documentacion_y_funciones>, filename='/u2/quiter/GEN4GL/PYPROGS/leer_documentacion_min.py', lineno=36, function='leer_documentacion_y_funciones', code_context=['        print(inspect.stack())\\n'], index=0, positions=Positions(lineno=36, end_lineno=36, col_offset=14, end_col_offset=29))]
Traceback (most recent call last):
  File "/u2/quiter/GEN4GL/PYPROGS/leer_documentacion_min.py", line 19, in leer_documentacion_y_funciones
    modulo = __import__(script)
             ^^^^^^^^^^^^^^^^^^
  File "/u2/quiter/GEN4GL/PYPROGS/lanza_metodo_min.py", line 7, in <module>
    import requests
  File "/usr/uv/python/lib/python3.11/site-packages/requests/__init__.py", line 48, in <module>
    from charset_normalizer import __version__ as charset_normalizer_version
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/__init__.py", line 24, in <module>
    from .api import from_bytes, from_fp, from_path, is_binary
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/api.py", line 5, in <module>
    from .cd import (
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/cd.py", line 14, in <module>
    from .md import is_suspiciously_successive_range
SystemError: initialization of md__mypyc did not return an extension module
Respuesta 1: KO - initialization of md__mypyc did not return an extension module
>

Why am I having this different behavior from the BASIC PyCallFunction?

How can I fix this issue?



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hi all.

I'm using the inspect module to extract information about our code. The code runs well in the Python console but when called from Universe Basic I'm getting a Python runtime error.

The Python side is really simple. I've reduced my code to a minimal example that reproduces it:

File: leer_documentacion_min.py

This is the module that does the inspection

import inspect
import json
import sys


def parameter_as_string(name, p):
    def_value = f' = {p.default}' if (not type(p.default) == type(inspect._empty)) else ''
    typ_annot = f':{p.annotation.__name__}' if (p.annotation.__name__ != '_empty') else ''
    return f'{name}{typ_annot}{def_value}'


def leer_documentacion_y_funciones(script):
    try:
        if script in sys.modules:
            sys.modules.pop(script)
        modulo = __import__(script)
        # rest of the code
        documentacion = modulo.__doc__ if modulo.__doc__ else 'Sin documentacion.'
        funciones = inspect.getmembers(modulo, inspect.isfunction)
        informacion_funciones = []
        for nombre, funcion_py in funciones:
            argumentos = inspect.signature(funcion_py).parameters
            lista_args = [parameter_as_string(p, argumentos[p]) for p in argumentos]
            informacion_funciones.append({'nombre': nombre, 'argumentos': '|'.join(lista_args)})

        sys.modules.pop(script)
        return json.dumps({
            'documentacion': documentacion,
            'numero_de_funciones': len(funciones),
            'informacion_funciones': informacion_funciones
        })
    except Exception as e:
        print(inspect.stack())
        import traceback
        traceback.print_exc()
        return f'KO - {e}'

File: lanza_metodo_min.py

This code is -mostly- irrelevant, as the part that reproduces the error is the first import.

import requests
import json


def lanza_metodo(client_id: str, client_secret: str, code: str, api: str, version: int, tipo_http: str, metodo: str):
    salida = False
    try:
        response_get = requests.get('https://community.rocketsoftware.com/home')
        salida = req.status_code == requests.codes.ok
    except Exception as err:
        print('Se ha producido un error general en la peticion ' + tipo_http + ' /' + metodo + ': ' + str(err))
    return salida

Now I write a simple BASIC UP:

RESPUESTA=PyCallFunction('leer_documentacion_min','leer_documentacion_y_funciones','lanza_metodo_min')
CRT 'Respuesta 1: ':RESPUESTA

When I run the code from the Python terminal it works fine, as expected:

SH-4.4$ /uv/python/bin/python3
Python 3.11.0 (main, Nov 16 2022, 04:47:09) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import leer_documentacion_min
>>> leer_documentacion_min.leer_documentacion_y_funciones('lanza_metodo_min')
'{"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}'
>>> leer_documentacion_min.leer_documentacion_y_funciones('lanza_metodo_min')
'{"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}'
>>> leer_documentacion_min.leer_documentacion_y_funciones('lanza_metodo_min')
'{"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}'
>>>

But when I run the BASIC UP from the TCL it starts to throw exceptions after the first call:

>RUN UP HCH_CRL
Respuesta 1: {"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}
>.X
01 RUN UP HCH_CRL
[FrameInfo(frame=<frame at 0x7f3518462440, file '/u2/quiter/GEN4GL/PYPROGS/leer_documentacion_min.py', line 36, code leer_documentacion_y_funciones>, filename='/u2/quiter/GEN4GL/PYPROGS/leer_documentacion_min.py', lineno=36, function='leer_documentacion_y_funciones', code_context=['        print(inspect.stack())\\n'], index=0, positions=Positions(lineno=36, end_lineno=36, col_offset=14, end_col_offset=29))]
Traceback (most recent call last):
  File "/u2/quiter/GEN4GL/PYPROGS/leer_documentacion_min.py", line 19, in leer_documentacion_y_funciones
    modulo = __import__(script)
             ^^^^^^^^^^^^^^^^^^
  File "/u2/quiter/GEN4GL/PYPROGS/lanza_metodo_min.py", line 7, in <module>
    import requests
  File "/usr/uv/python/lib/python3.11/site-packages/requests/__init__.py", line 48, in <module>
    from charset_normalizer import __version__ as charset_normalizer_version
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/__init__.py", line 24, in <module>
    from .api import from_bytes, from_fp, from_path, is_binary
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/api.py", line 5, in <module>
    from .cd import (
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/cd.py", line 14, in <module>
    from .md import is_suspiciously_successive_range
SystemError: initialization of md__mypyc did not return an extension module
Respuesta 1: KO - initialization of md__mypyc did not return an extension module
>

Why am I having this different behavior from the BASIC PyCallFunction?

How can I fix this issue?



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hector,

Please check that your code works when using the Python version supplied with UniVerse straight from an O.S Python execution. Otherwise it is worth checking the .pyconfig and  u2.pth files as UniVerse uses a specific and explicit search  order for modules. I also recommend using absolute paths.

Regards

JJ



------------------------------
John Jenkins
Thame, Oxfordshire
------------------------------


Hector,

Please check that your code works when using the Python version supplied with UniVerse straight from an O.S Python execution. Otherwise it is worth checking the .pyconfig and  u2.pth files as UniVerse uses a specific and explicit search  order for modules. I also recommend using absolute paths.

Regards

JJ



------------------------------
John Jenkins
Thame, Oxfordshire
------------------------------

John, I already tried using the Universe Python, look at the code segment that starts with

SH-4.4$ /uv/python/bin/python3

As for the .pyconfig and u2.pth files they seem correct:

SH-4.4$ cat  /uv/.pyconfig
PYHOME=/usr/uv/python
PYLIB=/usr/uv/python/lib/libpython3.11.so

SH-4.4$ cat /uv/python/lib/python3.11/site-packages/u2.pth
/usr/uv/bin
/usr/uv/XDEMO/PP
/u2/quiter/GEN4GL/PYPROGS

Where /u2/quiter/GEN4GL/PYPROGS is the path to my code.



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hector,

Please check that your code works when using the Python version supplied with UniVerse straight from an O.S Python execution. Otherwise it is worth checking the .pyconfig and  u2.pth files as UniVerse uses a specific and explicit search  order for modules. I also recommend using absolute paths.

Regards

JJ



------------------------------
John Jenkins
Thame, Oxfordshire
------------------------------

I've done another small example

This is the Python code (stored in /u2/quiter/GEN4GL/PYPROGS/json_import_test.py)

import traceback


def requests_test():
    ret_val = 'KO'
    try:
        import requests
        req = requests.get('https://quiter.com/')
        if req.status_code == requests.codes.ok:
            ret_val = 'OK'
    except Exception as err:
        traceback.print_exc()
        print(f'Se ha producido un error general en la peticion {err}')
        print(inspect.stack())
    print(ret_val)
    return ret_val


if __name__ == '__main__':
    requests_test()

This is the BASIC code, in an UP called HCH_CRL

RESPUESTA=PyCallFunction('json_import_test', 'requests_test')
CRT 'Respuesta 1: ':RESPUESTA

Execution with the Universe Python: it works across several executions

SH-4.4$ /uv/python/bin/python3 -m requests_import_test
OK
SH-4.4$ /uv/python/bin/python3 -m requests_import_test
OK
ASH-4.4$ /uv/python/bin/python3 -m requests_import_test
OK
ASH-4.4$ /uv/python/bin/python3 -m requests_import_test
OK

Execution from inside the Universe Python shell: it also works across several executions

SH-4.4$ /uv/python/bin/python3
Python 3.11.0 (main, Nov 16 2022, 04:47:09) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests_import_test
>>> requests_import_test.requests_test()
OK
'OK'
>>> requests_import_test.requests_test()
OK
'OK'
>>> requests_import_test.requests_test()
OK
'OK'
>>>

Execution via PyCallFunction: it fails after the first execution.

>RUN UP HCH_CRL
OK
Respuesta 1: OK
>RUN UP HCH_CRL
Traceback (most recent call last):
  File "/u2/quiter/GEN4GL/PYPROGS/json_import_test.py", line 6, in requests_test
    import requests
  File "/usr/uv/python/lib/python3.11/site-packages/requests/__init__.py", line 48, in <module>
    from charset_normalizer import __version__ as charset_normalizer_version
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/__init__.py", line 24, in <module>
    from .api import from_bytes, from_fp, from_path, is_binary
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/api.py", line 5, in <module>
    from .cd import (
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/cd.py", line 14, in <module>
    from .md import is_suspiciously_successive_range
SystemError: initialization of md__mypyc did not return an extension module
Se ha producido un error general en la peticion initialization of md__mypyc did not return an extension module
Respuesta 1: Line 4, Improper data type.
>

We need to be able to use imported modules in our Python code.

How can we fix this?



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------


Hi all.

I'm using the inspect module to extract information about our code. The code runs well in the Python console but when called from Universe Basic I'm getting a Python runtime error.

The Python side is really simple. I've reduced my code to a minimal example that reproduces it:

File: leer_documentacion_min.py

This is the module that does the inspection

import inspect
import json
import sys


def parameter_as_string(name, p):
    def_value = f' = {p.default}' if (not type(p.default) == type(inspect._empty)) else ''
    typ_annot = f':{p.annotation.__name__}' if (p.annotation.__name__ != '_empty') else ''
    return f'{name}{typ_annot}{def_value}'


def leer_documentacion_y_funciones(script):
    try:
        if script in sys.modules:
            sys.modules.pop(script)
        modulo = __import__(script)
        # rest of the code
        documentacion = modulo.__doc__ if modulo.__doc__ else 'Sin documentacion.'
        funciones = inspect.getmembers(modulo, inspect.isfunction)
        informacion_funciones = []
        for nombre, funcion_py in funciones:
            argumentos = inspect.signature(funcion_py).parameters
            lista_args = [parameter_as_string(p, argumentos[p]) for p in argumentos]
            informacion_funciones.append({'nombre': nombre, 'argumentos': '|'.join(lista_args)})

        sys.modules.pop(script)
        return json.dumps({
            'documentacion': documentacion,
            'numero_de_funciones': len(funciones),
            'informacion_funciones': informacion_funciones
        })
    except Exception as e:
        print(inspect.stack())
        import traceback
        traceback.print_exc()
        return f'KO - {e}'

File: lanza_metodo_min.py

This code is -mostly- irrelevant, as the part that reproduces the error is the first import.

import requests
import json


def lanza_metodo(client_id: str, client_secret: str, code: str, api: str, version: int, tipo_http: str, metodo: str):
    salida = False
    try:
        response_get = requests.get('https://community.rocketsoftware.com/home')
        salida = req.status_code == requests.codes.ok
    except Exception as err:
        print('Se ha producido un error general en la peticion ' + tipo_http + ' /' + metodo + ': ' + str(err))
    return salida

Now I write a simple BASIC UP:

RESPUESTA=PyCallFunction('leer_documentacion_min','leer_documentacion_y_funciones','lanza_metodo_min')
CRT 'Respuesta 1: ':RESPUESTA

When I run the code from the Python terminal it works fine, as expected:

SH-4.4$ /uv/python/bin/python3
Python 3.11.0 (main, Nov 16 2022, 04:47:09) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import leer_documentacion_min
>>> leer_documentacion_min.leer_documentacion_y_funciones('lanza_metodo_min')
'{"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}'
>>> leer_documentacion_min.leer_documentacion_y_funciones('lanza_metodo_min')
'{"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}'
>>> leer_documentacion_min.leer_documentacion_y_funciones('lanza_metodo_min')
'{"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}'
>>>

But when I run the BASIC UP from the TCL it starts to throw exceptions after the first call:

>RUN UP HCH_CRL
Respuesta 1: {"documentacion": "...", "numero_de_funciones": 1, "informacion_funciones": [{"nombre": "lanza_metodo", "argumentos": "client_id:str|client_secret:str|code:str|api:str|version:int|tipo_http:str|metodo:str"}]}
>.X
01 RUN UP HCH_CRL
[FrameInfo(frame=<frame at 0x7f3518462440, file '/u2/quiter/GEN4GL/PYPROGS/leer_documentacion_min.py', line 36, code leer_documentacion_y_funciones>, filename='/u2/quiter/GEN4GL/PYPROGS/leer_documentacion_min.py', lineno=36, function='leer_documentacion_y_funciones', code_context=['        print(inspect.stack())\\n'], index=0, positions=Positions(lineno=36, end_lineno=36, col_offset=14, end_col_offset=29))]
Traceback (most recent call last):
  File "/u2/quiter/GEN4GL/PYPROGS/leer_documentacion_min.py", line 19, in leer_documentacion_y_funciones
    modulo = __import__(script)
             ^^^^^^^^^^^^^^^^^^
  File "/u2/quiter/GEN4GL/PYPROGS/lanza_metodo_min.py", line 7, in <module>
    import requests
  File "/usr/uv/python/lib/python3.11/site-packages/requests/__init__.py", line 48, in <module>
    from charset_normalizer import __version__ as charset_normalizer_version
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/__init__.py", line 24, in <module>
    from .api import from_bytes, from_fp, from_path, is_binary
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/api.py", line 5, in <module>
    from .cd import (
  File "/usr/uv/python/lib/python3.11/site-packages/charset_normalizer/cd.py", line 14, in <module>
    from .md import is_suspiciously_successive_range
SystemError: initialization of md__mypyc did not return an extension module
Respuesta 1: KO - initialization of md__mypyc did not return an extension module
>

Why am I having this different behavior from the BASIC PyCallFunction?

How can I fix this issue?



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hector,

This looks to be due to the re-initialization of Python UniVerse and UniData do by default. Some python packages do not support this reinit.

Try this from a fresh UV session.

>REINIT.PYTHON OFF

>RUN UP HCH_CRL

>.X

If this is the issue, you can modify the LOGIN to include the REINIT.PYTHON OFF line, as it will default back to ON after logoff.

Regards,

Dave Weinstein



------------------------------
Dave Weinstein
Associate Technical Support Engineer
Rocket Internal - All Brands
------------------------------

Hector,

This looks to be due to the re-initialization of Python UniVerse and UniData do by default. Some python packages do not support this reinit.

Try this from a fresh UV session.

>REINIT.PYTHON OFF

>RUN UP HCH_CRL

>.X

If this is the issue, you can modify the LOGIN to include the REINIT.PYTHON OFF line, as it will default back to ON after logoff.

Regards,

Dave Weinstein



------------------------------
Dave Weinstein
Associate Technical Support Engineer
Rocket Internal - All Brands
------------------------------

Hi Hector

I remember hitting this exact problem before Rocket added the REINIT support, and ended up dumping the requests module in favour of using http.client. That has seemed more stable.

Effectively the requests.get() becomes:

import http.client

...

def myMethod(self):

   conn = http.client.HTTPConnection(self.host, self.port)

   conn.request("GET",url)

   response = conn.getresponse()

   result = response.read()

   conn.close()

   return result

Brian



------------------------------
Brian Leach
Director
Brian Leach Consulting
Chipping Norton GB
------------------------------

Hector,

This looks to be due to the re-initialization of Python UniVerse and UniData do by default. Some python packages do not support this reinit.

Try this from a fresh UV session.

>REINIT.PYTHON OFF

>RUN UP HCH_CRL

>.X

If this is the issue, you can modify the LOGIN to include the REINIT.PYTHON OFF line, as it will default back to ON after logoff.

Regards,

Dave Weinstein



------------------------------
Dave Weinstein
Associate Technical Support Engineer
Rocket Internal - All Brands
------------------------------

Thanks Dave

That solved the issue and now it's working fine.



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hector,

This looks to be due to the re-initialization of Python UniVerse and UniData do by default. Some python packages do not support this reinit.

Try this from a fresh UV session.

>REINIT.PYTHON OFF

>RUN UP HCH_CRL

>.X

If this is the issue, you can modify the LOGIN to include the REINIT.PYTHON OFF line, as it will default back to ON after logoff.

Regards,

Dave Weinstein



------------------------------
Dave Weinstein
Associate Technical Support Engineer
Rocket Internal - All Brands
------------------------------

Hi, Dave

I'm finding again this issue, even with the REINIT.PYTHON flag set to OFF:

This is the Python code.

def import_requests_failure():
    try:
        import requests
        print('requests imported')
    except Exception as err:
        print(inspect.stack())
        traceback.print_exc()
        return 'KO'
    return 'OK'

This is the error appearing again, even if REINIT.PYTHON is switched off.

>REINIT.PYTHON STATUS
Current REINIT.PYTHON status:  OFF
>U_HECTOR_2
requests imported
RESPUESTA = OK
>U_HECTOR_2
[FrameInfo(frame=<frame at 0x7ff4146d27a0, file '/u2/quiter/GEN4GL/PYPROGS/request_import_err.py', line 10, code import_requests_failure>, filename='/u2/quiter/GEN4GL/PYPROGS/request_import_err.py', lineno=10, function='import_requests_failure', code_context=['        print(inspect.stack())\\n'], index=0, positions=Positions(lineno=10, end_lineno=10, col_offset=14, end_col_offset=29))]
Traceback (most recent call last):
  File "/u2/quiter/GEN4GL/PYPROGS/request_import_err.py", line 6, in import_requests_failure
    import requests
  File "/usr/uv/python/lib/python3.11/site-packages/requests/__init__.py", line 48, in <module>
    from charset_normalizer import __version__ as charset_normalizer_version
  File "/u2/usuarios/dsgenerico/.local/lib/python3.11/site-packages/charset_normalizer/__init__.py", line 24, in <module>
    from .api import from_bytes, from_fp, from_path
  File "/u2/usuarios/dsgenerico/.local/lib/python3.11/site-packages/charset_normalizer/api.py", line 5, in <module>
    from .cd import (
  File "/u2/usuarios/dsgenerico/.local/lib/python3.11/site-packages/charset_normalizer/cd.py", line 9, in <module>
    from .md import is_suspiciously_successive_range
SystemError: initialization of md__mypyc did not return an extension module
RESPUESTA = KO
>



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hi, Dave

I'm finding again this issue, even with the REINIT.PYTHON flag set to OFF:

This is the Python code.

def import_requests_failure():
    try:
        import requests
        print('requests imported')
    except Exception as err:
        print(inspect.stack())
        traceback.print_exc()
        return 'KO'
    return 'OK'

This is the error appearing again, even if REINIT.PYTHON is switched off.

>REINIT.PYTHON STATUS
Current REINIT.PYTHON status:  OFF
>U_HECTOR_2
requests imported
RESPUESTA = OK
>U_HECTOR_2
[FrameInfo(frame=<frame at 0x7ff4146d27a0, file '/u2/quiter/GEN4GL/PYPROGS/request_import_err.py', line 10, code import_requests_failure>, filename='/u2/quiter/GEN4GL/PYPROGS/request_import_err.py', lineno=10, function='import_requests_failure', code_context=['        print(inspect.stack())\\n'], index=0, positions=Positions(lineno=10, end_lineno=10, col_offset=14, end_col_offset=29))]
Traceback (most recent call last):
  File "/u2/quiter/GEN4GL/PYPROGS/request_import_err.py", line 6, in import_requests_failure
    import requests
  File "/usr/uv/python/lib/python3.11/site-packages/requests/__init__.py", line 48, in <module>
    from charset_normalizer import __version__ as charset_normalizer_version
  File "/u2/usuarios/dsgenerico/.local/lib/python3.11/site-packages/charset_normalizer/__init__.py", line 24, in <module>
    from .api import from_bytes, from_fp, from_path
  File "/u2/usuarios/dsgenerico/.local/lib/python3.11/site-packages/charset_normalizer/api.py", line 5, in <module>
    from .cd import (
  File "/u2/usuarios/dsgenerico/.local/lib/python3.11/site-packages/charset_normalizer/cd.py", line 9, in <module>
    from .md import is_suspiciously_successive_range
SystemError: initialization of md__mypyc did not return an extension module
RESPUESTA = KO
>



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hector,

The setting for REINIT.PYTHON effects what happens when a program returns to TCL, so if you ran the program with REINIT.PYTHON ON, then turned it OFF, it is already too late.  The process attempted to reinitialize the Python space, but could not due to the nature of the module imported.

Can you show us all the steps to get the error.  

i.e.   

1. Start a new process

2. REINIT.PYTHON OFF

3. run your program and see it work, and return to TCL

4. run again and see it fail.    



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Hi, Dave

I'm finding again this issue, even with the REINIT.PYTHON flag set to OFF:

This is the Python code.

def import_requests_failure():
    try:
        import requests
        print('requests imported')
    except Exception as err:
        print(inspect.stack())
        traceback.print_exc()
        return 'KO'
    return 'OK'

This is the error appearing again, even if REINIT.PYTHON is switched off.

>REINIT.PYTHON STATUS
Current REINIT.PYTHON status:  OFF
>U_HECTOR_2
requests imported
RESPUESTA = OK
>U_HECTOR_2
[FrameInfo(frame=<frame at 0x7ff4146d27a0, file '/u2/quiter/GEN4GL/PYPROGS/request_import_err.py', line 10, code import_requests_failure>, filename='/u2/quiter/GEN4GL/PYPROGS/request_import_err.py', lineno=10, function='import_requests_failure', code_context=['        print(inspect.stack())\\n'], index=0, positions=Positions(lineno=10, end_lineno=10, col_offset=14, end_col_offset=29))]
Traceback (most recent call last):
  File "/u2/quiter/GEN4GL/PYPROGS/request_import_err.py", line 6, in import_requests_failure
    import requests
  File "/usr/uv/python/lib/python3.11/site-packages/requests/__init__.py", line 48, in <module>
    from charset_normalizer import __version__ as charset_normalizer_version
  File "/u2/usuarios/dsgenerico/.local/lib/python3.11/site-packages/charset_normalizer/__init__.py", line 24, in <module>
    from .api import from_bytes, from_fp, from_path
  File "/u2/usuarios/dsgenerico/.local/lib/python3.11/site-packages/charset_normalizer/api.py", line 5, in <module>
    from .cd import (
  File "/u2/usuarios/dsgenerico/.local/lib/python3.11/site-packages/charset_normalizer/cd.py", line 9, in <module>
    from .md import is_suspiciously_successive_range
SystemError: initialization of md__mypyc did not return an extension module
RESPUESTA = KO
>



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Héctor,

I replied in the support case you opened where we were able to successfully show your program working multiple times in a fresh UV session.

Mike is spot on with his answer. The REINIT setting must be set before importing any modules to take effect in that session.

You can add the REINIT.PYTHON OFF to LOGIN paragraph of the account, or set programmatically via Python or BASIC if useful as well.

Regards,

Dave Weinstein



------------------------------
Dave Weinstein
Associate Technical Support Engineer
Rocket Internal - All Brands
------------------------------

Héctor,

I replied in the support case you opened where we were able to successfully show your program working multiple times in a fresh UV session.

Mike is spot on with his answer. The REINIT setting must be set before importing any modules to take effect in that session.

You can add the REINIT.PYTHON OFF to LOGIN paragraph of the account, or set programmatically via Python or BASIC if useful as well.

Regards,

Dave Weinstein



------------------------------
Dave Weinstein
Associate Technical Support Engineer
Rocket Internal - All Brands
------------------------------

The problem seemed to be a bad design in the LOGIN code, that wasn't setting REINIT.PYTHON in some cases.

As a follow up question, is there any way to know if a Universe installation has Python from Basic code? Any system variable, similar to PYEXCEPTIONMSG, for example?



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------