Put self.dbcon in the MyFactory class. MyProtocol instances can access it via self.factory.<br><br><br><div class="gmail_quote">On Tue, Mar 24, 2009 at 6:10 PM, Pet <span dir="ltr">&lt;<a href="mailto:petshmidt@googlemail.com">petshmidt@googlemail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
<br>
I&#39;ve wrote an daemon which does some queries to db and sends response<br>
back to client. Do I need to make for every request from client (new<br>
instance of  MyProtocol) a new connection to DB? Or can I somehow<br>
prepare connection, so I could save some time? Maybe make connection<br>
in Factory and pass it to Protocol? But what happens if too much<br>
clients are connected to server? What is the way to control it?<br>
<br>
Regards, Pet<br>
<br>
<br>
class MyProtocol(basic.LineReceiver):<br>
<br>
    def __init__(self):<br>
        print &quot;new connection&quot;<br>
        self.dbcon = adbapi.ConnectionPool(&quot;pyPgSQL.PgSQL&quot;,<br>
database=&quot;data&quot;, user=&#39;pet&#39;, host=&#39;local&#39;, password=&#39;some&#39;)<br>
<br>
<br>
class MyFactory(protocol.ServerFactory):<br>
    protocol = MyProtocol<br>
<br>
class MyService(internet.TCPServer):<br>
    def __init__(self):<br>
        internet.TCPServer.__init__(self,PORT,MyFactory())<br>
<br>
def main():<br>
    reactor.listenTCP(PORT, MyFactory())<br>
    reactor.run()<br>
<br>
<br>
if __name__ == &#39;__main__&#39;:<br>
    main()<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.alvinatorsplayground.blogspot.com/">http://www.alvinatorsplayground.blogspot.com/</a><br>