[Python] Сonnection timeout for function does not seem to work in Python script

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    for some reason the connection timeout does not seem to work when connecting to a Firebird database. For example, if an incorrect IP address is specified, the script hangs and waits for a long time.

    #!/usr/bin/python3

    import fdb
    import timeout


    HOST = '172.19.76.10'
    DBS = [
    'test_db_1102',
    'test_db_10025',
    'test_catalog',
    ]
    USER = 'SYSDBA'
    PASSWORD = '123'


    def check_db(DB):
    print(DB)
    con = fdb.connect(host = HOST, database = DB, user = USER, password = PASSWORD )
    cur = con.cursor()
    cur.execute('select first(1) * from objects')
    print(cur.fetchall())


    for DB in DBS:
    timeout.timeout_check(check_db(DB),5)



    list timeout.py:

    #!/usr/bin/python3


    import multiprocessing
    import time


    def timeout_check(func, func_timeout):
    p = multiprocessing.Process(target=func)
    p.start()
    p.join(func_timeout)

    if p.is_alive():
    print ("running... let's kill it...")
    p.terminate()
    p.join()




    I tried using other timeout functions based on the signal library, but that also does not work

    Continue reading...

Compartilhe esta Página