Skip to main content

Hi

As I posted in another thread, I'm trying to port some code from uopy to u2py but I can't debug the code properly.

I'm using Visual Studio code, connected remotely to a server via ssh.

I have a really simple launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug manual launch",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/test_file.py",
            "python": "/u2/uv/python/bin/python3",
            "console": "integratedTerminal",
            "justMyCode": false,
            "args": [],
            "cwd": "${workspaceFolder}",
            "env": {"PYTHONPATH": "${workspaceFolder}:${env:PYTHONPATH}"}
        }
    ]
}

The test file is something very simple:

def test_u2py():
    import u2py        
    c = u2py.Command('WHO', capture=True)
    l = c.run()
    print(l)
    return l

And I can call it from BASIC:

NOMBRE.SCRIPT='test_file'
NOMBRE.FUNCION='test_u2py'
RESPUESTA=PyCallFunction(NOMBRE.SCRIPT,NOMBRE.FUNCION)
CRT RESPUESTA

But when I try to run it the interpreter just crashes and exits. I guess u2py expects some kind of "session" and is not finding it, so it fails (breaking the python interpreter, also).


Is there a way to debug u2py code from the terminal?

I tried this experiment, but it doesn't work

def test_u2py():
    with uopy.connect(host='', user='', password='', account='') as s:        
        c = u2py.Command('WHO', capture=True)
        l = c.run()
        print(l)


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

Hi

As I posted in another thread, I'm trying to port some code from uopy to u2py but I can't debug the code properly.

I'm using Visual Studio code, connected remotely to a server via ssh.

I have a really simple launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug manual launch",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/test_file.py",
            "python": "/u2/uv/python/bin/python3",
            "console": "integratedTerminal",
            "justMyCode": false,
            "args": [],
            "cwd": "${workspaceFolder}",
            "env": {"PYTHONPATH": "${workspaceFolder}:${env:PYTHONPATH}"}
        }
    ]
}

The test file is something very simple:

def test_u2py():
    import u2py        
    c = u2py.Command('WHO', capture=True)
    l = c.run()
    print(l)
    return l

And I can call it from BASIC:

NOMBRE.SCRIPT='test_file'
NOMBRE.FUNCION='test_u2py'
RESPUESTA=PyCallFunction(NOMBRE.SCRIPT,NOMBRE.FUNCION)
CRT RESPUESTA

But when I try to run it the interpreter just crashes and exits. I guess u2py expects some kind of "session" and is not finding it, so it fails (breaking the python interpreter, also).


Is there a way to debug u2py code from the terminal?

I tried this experiment, but it doesn't work

def test_u2py():
    with uopy.connect(host='', user='', password='', account='') as s:        
        c = u2py.Command('WHO', capture=True)
        l = c.run()
        print(l)


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

Hector,

Your current working directory must be a U2 account when importing u2py.  If not, the python process exits.

i.e.

C:\\temp\\not_an_account>python
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import u2py
Error msgno = 427. args = VOC
errno=2: No such file or directory

 

Note that you can use python code to set the current working directory

i.e. 

C:\\temp\\not_an_account>python
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.chdir('/U2/ud83/XDEMO')
>>> import u2py
Current REINIT.PYTHON status: OFF

Welcome to the XDEMO Account
Version: 3.1.5

>>>



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