Problem connecting with LO as server

Good Afternoon

I am having problem connecting to LO as server. The python code exits without any kind of error. I start LO in the following way:

soffice --accept="socket,port=2002;urp;StarOffice.ComponentContext"

as well as

soffice --accept="socket,port=2002;urp;StarOffice.ComponentContext" --calc

My python code is:

import socket
import uno

def open_calc(thepathtodoc):
    local_ctx = uno.getComponentContext()
    smgr_local = local_ctx.ServiceManager
    resolver = smgr_local.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local_ctx)
    url = "uno:socket,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext"
    uno_ctx = resolver.resolve(url)
    thedocurl = uno.systemPathToFileUrl(thepathtodoc)
    try:
        print(2)
        adesktop = smgr_local.createInstanceWithContext("com.sun.star.frame.Desktop",uno_ctx )
        print(3)
        thedocurl = uno.systemPathToFileUrl(thepathtodoc)
        print(4)
        return adesktop.loadComponentFromURL(thedocurl,"_blank",0,[])
    except Exception as e:
        print(e)
def getCurrentRegion(oRange):
    """Get current region around given range."""
    oCursor = oRange.getSpreadsheet().createCursorByRange(oRange)
    oCursor.collapseToCurrentRegion()
    return oCursor

if __name__ == '__main__':
    print(1)
    the_doc=open_calc(r"e:\Documents\numeric_data_source.ods")
    print(4)
    sh = the_doc.Sheets.getByIndex(0)
    cr = getCurrentRegion(sh.getCellByPosition(0,0))
    cra = cr.getRangeAddress()

    sc = cra.StartColumn
    sr =  cra.StartRow+1

    ec = cra.EndColumn
    er =  cra.EndRow

    rg = cr.getCellRangeByPosition(sc, sr, ec, er)
    da_array=rg.getDataArray()
    the_doc.close(True)

here is the output:

E:\Program Files\LibreOffice\program>python e:\Documents\hello_world.py
1
2

E:\Program Files\LibreOffice\program>

As you can see there is no exception, but code terminates.

Between opening and closing a document, your code does nothing

As you can see, python exits on the attempt to connect to the LO instance