Something like this:<br><br>from twisted.protocols import basic<br>from twisted.internet import protocol, reactor<br>from twisted.enterprise import adbapi<br><br>class MyProtocol(basic.LineReceiver):<br>    def __init__(self):<br>
        pass<br><br>    def lineReceived(self, line):<br>        ### dbcon can be accessed via self.factory<br>        print dir(self.factory.dbcon)<br><br>class MyFactory(protocol.ServerFactory):<br>    protocol = MyProtocol<br>
    def __init__(self):<br>        self.dbcon = adbapi.ConnectionPool(&quot;pyPgSQL.PgSQL&quot;, database=&quot;data&quot;, user=&#39;pet&#39;, host=&#39;local&#39;, password=&#39;some&#39;)<br><br>if __name__ == &quot;__main__&quot;:<br>
    reactor.listenTCP(8080, MyFactory())<br>    reactor.run()<br><br>I usually put persistent data on the factory so that protocol instances can access them such as {username:&lt;protocol instance&gt;} dictionary for chatroom server.<br>
<br><br><br><div class="gmail_quote">On Wed, Mar 25, 2009 at 12:22 AM, 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;">
<div class="im">On Tue, Mar 24, 2009 at 5:04 PM, Rob Hoadley &lt;<a href="mailto:hoadley@gmail.com">hoadley@gmail.com</a>&gt; wrote:<br>
&gt; You&#39;d want to use a connection pool to manage the db interaction.<br>
&gt; Your server is pretty unusable after a db connection failure.  I&#39;ve<br>
&gt; used the connection pool before with a cp_min of 1 and a cp_max of 2.<br>
<br>
</div>Honestly speaking, I don&#39;t understand, what does it mean.<br>
I&#39;m already using connection pool with default cp_min an max, don&#39;t I?<br>
Could you explain me, as for a newbie, please<br>
<div><div></div><div class="h5"><br>
&gt;<br>
&gt; <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.enterprise.adbapi.ConnectionPool.html" target="_blank">http://twistedmatrix.com/documents/8.2.0/api/twisted.enterprise.adbapi.ConnectionPool.html</a><br>

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