I am pretty new to python and am using pythons SocketServer.ForkingTCPServer to create a network script that needs to connect to a database(mysql). I expect the program to get hit at around 30 - 40 times a second. Is it possible to share the same database connection across the processes?
import os import SocketServer import MySQLdb class EchoHandler(SocketServer.StreamRequestHandler): def handle(self): self.wfile.write("SET VARIABLE DBDIALSTRING dbstuff \n") self.wfile.flush() self.conn.close() if __name__ == '__main__': conn = MySQLdb.connect (host = "10.0.0.12", user = "dbuser", passwd = "secert", db = "dbname") SocketServer.ForkingTCPServer.allow_reuse_address = 1 server = SocketServer.ForkingTCPServer(('10.0.0.10', 4242), EchoHandler) print "Server listening on localhost:4242..." try: server.allow_reuse_address server.serve_forever() except KeyboardInterrupt: print "\nbailing..."