Rocket U2 | UniVerse & UniData

 View Only

 u2py : connection understanding

Manu Fernandes's profile image
PARTNER Manu Fernandes posted 02-17-2022 12:53
hello,

If I want to use U2PY (not UOPY)  I do not understand what type of connection (identification/authentification) occurs ?  Is it a heritance of the current (shell) session on the server ? 

and by the way which uvengine is used ? (uvsh, uvapi_..., ?) .  

Thanks for any detail.
Manu
John Jenkins's profile image
ROCKETEER John Jenkins
Manu -

UOPY is UniObjects-based - please see https://www.rocketsoftware.com/product-categories/modernization/multivalue. It will operate in the same way as any other UniObjects-based client application.

U2PY can be invoked in one of two ways:
  • Python can be invoked in the server O/S environment - the Python code can make calls into the database and will take a database license as it does so.
  • Python can be invoked from inside a U2 database shell as a separate environment.
    • It can be called as a subroutine with arguments passed each way.
    • It can be executed as a Python command - operating independently of the U2 database. Other than the O/S execution environment nothing is explicitly shared.

Hopefully this clarification helps.
Manu Fernandes's profile image
PARTNER Manu Fernandes
Hi John,
Thanks for the reply.

Yes, UOPY (uopy · PyPI) is a uniObject for Python via unirpc.

But if U2PY (UniVerse_PythonUserGuide_V1134 - page 32) is unirpc based, why the sample do not request connection arguments?
Into U2PY module (python.dir(u2py)), there is no session object, no connect() method. 
I suppose it run only in u2 server console mode with current user credential. 

Can anyone confirm it ? 

Manu
Manu Fernandes's profile image
PARTNER Manu Fernandes
so, after a sample test : 
PROGRAM TESTPY
CRT 'WHO=' : @WHO
CRT 'LOGNAME=' : @LOGNAME
CRT 'TTY=':@TTY
CMD = 'LISTU'; GOSUB RUNIT
CMD = 'LISTUSER DETAIL'; GOSUB RUNIT
CMD = 'PORT.STATUS'; GOSUB RUNIT
CMD = 'PORT.STATUS LAYER.STACK PORT ' : @USERNO; GOSUB RUNIT
CMD = 'DOS /C uvlictool'; GOSUB RUNIT
INPUT K
STOP



RUNIT:
CRT CMD : STR('-', 20)
EXECUTE CMD
RETURN

from os shell, 
PS C:\u2\uv> .\python\python.exe

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> import u2py
>>> u2py.run("BASIC BP TESTPY")
Compiling: Source = 'BP/TESTPY', Object = 'BP.O/TESTPY'
*
Compilation Complete.

>>> u2py.run("RUN BP TESTPY")
WHO=uv
LOGNAME=INFODATA\efv
TTY=console

LISTU--------------------

These are the UniVerse users presently sharing the system.
        uid      Pid  User Name             Terminal No      Login Time
*         0     1688  efv                   console:1688     Feb 23 18:21
There are currently 1 users logged on the system.


LISTUSER DETAIL--------------------
UsrNo Pid...... UID.. UserName Type Acct.............. LogonTime...............
    2      1688     0 efv      Term C:\u2\uv           Wed Feb 23 18:21:25 2022

Total lines returned: 1
PORT.STATUS--------------------

There are currently 0 uniVerse sessions; 1 interactive, -1 phantom

  Pid....  User name.  Who...  Port name.....  Last command processed..........
     1688  efv              2  Unknown         Unavailable


PORT.STATUS LAYER.STACK PORT 2--------------------

There are currently 0 uniVerse sessions; 1 interactive, -1 phantom

  Pid....  User name.  Who...  Port name.....  Last command processed..........
     1688  efv              2  Unknown         Unavailable
DOS /C uvlictool--------------------
Device licensing is in effect.
No.   Pid      Package  Device name             IP address      Device sub-key
1     1688
1 license seats are in use.
0 license seats are available.​


at os side the pid is

PS C:\u2\uv> GET-PROCESS -PID 1688 -Verbose | format-list *
Name                       : python
Id                         : 1688
FileVersion                : 3.7.3
Path                       : C:\u2\uv\python\python.exe

As we can read,
TTY is console, LOGNAME is current OS user.
LISTU report a Term and LISTUSER report a console !
PORT.STATUS is Unknown Unavailable
UVLICTOOL do not report PY Package nor anything

at OS, there is no sub-process to run uv, it's pure python . 
 
Okay, noted.
John Jenkins's profile image
ROCKETEER John Jenkins
Manu,

While UOPY uses UniObjects, U2PY runs as a console session on Windows or a UNIX shell and program as appropriate for the O/S and does not operate as a client-server application. So when you access a database function it is just like running a database shell from the O/S level - it is just invoked indirectly from the O/S python command.

Here is an example where user 3 is a Python program invoking a UniData subroutine on Windows.  I just used GetMemberInfo.py in the XDEMO account and added a SLEEP to the subroutine that was called so it stayed resident long enough for me to spot the process. If wished, the same approach can be taken on UNIX to see the absolute detail, just make sure you pick up the Python binary that we supply and not the UNIX default version.

:listuser

Licensed(UDT+CP)/Effective Udt Sql iPhtm Pooled Total

( 24 + 4 ) / 28 3 0 0 0 3

UDTNO USRNBR UID USRNAME USRTYPE TTY IP-ADDRESS TIME DATE
1 16872 305664 jjenkins udt pts/1 172.17.208.1 17:30:41 Feb 23 2022
2 36324 305664 jjenkins udt pts/2 Console 17:32:55 Feb 23 2022
3 75008 305664 jjenkins udt pts/3 Console 17:35:24 Feb 23 2022
Mike Rajkowski's profile image
ROCKETEER Mike Rajkowski
Manu,

Yes, UniVerse and Python ( when using the u2py ) will share the same process.

You can also see which process started first with sys.executable

i.e.
C:\U2\UV>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import u2py
>>> u2py.run("WHO")
2 UV From ROCKET1\mrajkowski
>>> import sys
>>> sys.executable
'C:\\U2\\UV\\python\\python.exe'
>>>

or when starting uv first:
>WHO
2 UV From ROCKET1\mrajkowski
>PYTHON
python> import sys
python> sys.executable
'C:\\U2\\UV\\BIN\\uv.exe'
Jean Lemonnier's profile image
ROCKETEER Jean Lemonnier
Bonjour Manu,

This is for MV servers the detail:

1 - UOPY works with API defined in the unirpcservices file used by UOSERVER (unirpcd redirects to uvapi_server and uvapi_slave to exchange with MV server U2 or Unidata) as you use service='uvcs' by default ('udcs' if Unidata) on port 31438.
With sess=uopy.connect(...) you pass the user and password of the O/S.
sess.close() closes the session.
By analogy, on D3, UOPY works with API defined in the d3services file used by UOSERVER (d3netsvc redirects to d3api_server and d3api_slave to exchange with MV server D3) you want to have 'authentication on' else this is user and password of D3.

2 - U2PY - uses an embedded version of Python 3.4 on 11.3.1, 3.7 on 11.3.2/12.1.1, 3.9 on 11.3.3

U2PY works in native with the python version defined in .pyconfig file, it uses same user than U2 start. You have no user and password as this is native.

3 - D3PY - uses only version 3.7 of Python on D3 10.3
D3PY works in native with the python version defined in .pyconfig file
You want to use the same user and password than uopy with or without authentication (o/s or D3 users)
d3py.logon(machine, user, password, md, md_password) machine (pick0) is the name of Linux or AIX machine or 127.0.0.1 for Windows
d3py.logoff() to logoff
On D3 it uses ODBC license as this OnlyDevelopedByC (Python and SQL use ODBC license).

U2PY and D3PY work only on the same machine as MV server (respectively U2 or Unidata and D3).

This is recommended to create a specific user to differentiate the type of application Python/telnet/ODBC/... on the session connected.

Best regards,

Jean
Kurt KONCHADI's profile image
Kurt KONCHADI
I wanted to echo a similar question as Manu. I am using u2py in a SB+ enabled account. While running functions such as u2py.run('WHO'), the python script triggers the LOGIN paragraph, which invoked SB+ login. Any solution to this?