[cx-oracle-users] wrong subprocess.call() return after use cx_Oracle
Brought to you by:
atuining
From: Anderson C. T. <and...@op...> - 2020-05-29 03:24:42
|
Hi list, I’m facing a strength behaviour on a Python project (the first one I’m using cx_Oracle). Scenario: This python application must access database and get some simple data (query returning two columns and no more than 4 or 5 rows). After run this query, I must call invoke a shell script from my Python code and I must check the retcode, returned by the shell. The problem is that subprocess.call() always return 0 (zero) as retcode from shell (even when shell explicitly exit with any other retcode), and this is happening only If a use cx_Oracle. My environment: Oracle Linux 7.7 Python 2.7.5 Oracle 11.2.0.4 I could reproduce this problem with a simple test case that I’m sending below. Please my apologies by any english mistakes. testenv.py file # -*- coding: latin-1 -*- ''' Created on 28 de mai de 2020 ''' from os import environ from execshell import TestClass def entrypoint(): environ['ORACLE_HOME'] = '/u01/app/oracle/product/11.2.0.4/dbhome_ee' environ['ORACLE_SID'] = 'orcl' x = TestClass() x.exec_shell() x.exec_query() x.exec_shell() if __name__=='__main__': entrypoint() execshell.py file # -*- coding: latin-1 -*- ''' Created on 28 de mai de 2020 ‘'' import cx_Oracle from subprocess import call class TestClass(object): def __init__(self): self.rman_configs = None def exec_shell(self): print 'TestClass::exec_shell()' rc = call('/tmp/orcl-callback.sh') print 'TestClass::exec_shell() -> os.call returned code {} from shell'.format(rc) def exec_query(self): conn = None cur = None print 'TestClass::exec_query(). Running seelect hello from dual' try: conn = cx_Oracle.connect(mode=cx_Oracle.SYSDBA) cur = conn.cursor() cur.execute("select 'hello' from dual") for v in cur: print v except cx_Oracle.Error as e1: raise e1 finally: if cur: cur.close() if conn: conn.close() the called shell script (oral-callback.sh): #!/bin/bash echo " This is a echo from shell script" echo " The shell will simulate an error, returning non zero code" sleep 2 exit 125 |