python - Keeping a connection open for the purposes of testing -


I am trying to test a database where I open the X number of the axle connection, when I against the database Run a transaction set database. That being said, I have started creating some arguments to open the connection to the database:

  import socket df open_connect (hostname, port): "makes a socket connection" Which function: Hostname: To connect to Hostname: Port: Port to connect to host. "" "" Ipaddr = socket.gethostbyname sock = socket.socket (socket.AFNAAT, socket.SOCKRRMAM) sock.connect ((ipad, port)) Sock.close () def main (): "" "main The task "" "" open_connect ('somedb', 3306) If __name__ == "__main__": main ()   

I need to be added now that there is some argument which Can anyone please provide the connection on the best way to open a DB connection, while I will answer the actual questions. I will thank you in advance.

I think I try to use a library such as MySQLdb that you do not want to use sockets.

  Import MySQLdb # connect con = MySQLdb.connect (host = "localhost",   

You will be able to check whether the connection is using the ping method: pre> def is_connection_up ( Connection): if connection.ping () == 0: returns are correct: Return Return

Then you can do something like this:

  import MySQLdb import time def is_connection_up (connection): if connection.ping () == 0: Returns correct second: wrong host, user, pwd, db = "localhost", "user", "pwd", "db" connection = [ MySQLDB.Connect (host = host, user = user, passwd = pwd, db = db) for category (10)] while correct: time.sleep (10) for connection in the election: if_connec Tion_up (con) is not correct: taking exception ("the connection is down, the test may have gone wrong")    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -