1

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

asked Aug 28, 2025 at 14:43
1
  • what lib your import timeout is importing ? Apart the answer (I was writing the same thing in a comment and then cancel it) you can also look at Timeout on a function call if needed Commented Aug 28, 2025 at 15:07

1 Answer 1

3

Your timeout_check function accepts a function as a first argument, yet you're passing in the results of a function call check_db(DB), i.e. this function is called immediately.

You probably want to send a partially applied function to timeout_check:

from functools import partial
...
for DB in DBS:
 timeout.timeout_check(func=partial(check_db, DB), func_timeout=5)
answered Aug 28, 2025 at 14:59
Sign up to request clarification or add additional context in comments.

1 Comment

May be also the OP missed a decorateur for timeout_check ? But I don't know which lib the OP get doing import timeout

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.