Hi,<div><br></div><div>I&#39;m working on creating a server/client bit of software using threading and sockets (it&#39;s a project so I can&#39;t use something like twisted), and I&#39;ve run into a slight issue with my server. My server currently looks like this:</div>

<div><br></div><div><div>class ClientThread(threading.Thread):</div><div>    def __init__(self, socketdata, server):</div><div>        threading.Thread.__init__(self)</div><div>        self.conn = socketdata[0]</div><div>

        self.details = socketdata[1]</div><div>        self.server = server</div><div><br></div><div>    def run(self):</div><div>        &#39;&#39;&#39; Method called when the Thread.start() method is called. &#39;&#39;&#39;</div>

<div>        global CONNCOUNT</div><div>        CONNCOUNT -= 1</div><div>        print(&quot;Getting data from {0}:{1}: &quot;.format(self.details[0],</div><div>                                                 self.details[1]), end=&#39;&#39;)</div>

<div>        data = self.conn.recv(1024)</div><div>        print(data)</div><div>        if data == &#39;quit&#39;:</div><div>            self.server.stop()</div><div>        self.conn.close()</div><div><br></div><div><br>

</div><div>class Server(threading.Thread):</div><div>    def __init__(self, port=1500, max_connections=5):</div><div>        &#39;&#39;&#39; Setup the server elements. &#39;&#39;&#39;</div><div><br></div><div>        threading.Thread.__init__(self)</div>

<div>        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</div><div>        self.server.bind((&#39;localhost&#39;, 1500))</div><div>        self.server.listen(5)</div><div>        self.keeprunning = True</div>

<div><br></div><div>    def run(self):</div><div>        global CONNCOUNT</div><div>        while self.keeprunning:#CONNCOUNT &gt; 1: </div><div>            ClientThread(self.server.accept(), self).start()</div><div>        self.stop()</div>

<div><br></div><div>    def stop(self):</div><div>        &#39;&#39;&#39; Stop the server. &#39;&#39;&#39;</div><div><br></div><div>        print(&quot;Stopping server... maybe...&quot;)</div><div>        self.keeprunning = False</div>

<div>        # Close the socket connection</div><div>        self.server.close()</div><div>        print(&quot;Server stopped.&quot;)</div></div><div><br></div><div>(CONNCOUNT is currently not used - I was using it to stop my server)</div>

<div><br></div><div>My issue is that when I send &#39;quit&#39; the server does (sort of) close, but (I think) the self.server.accept() is blocking, so until I try connecting a few more times, the server doesn&#39;t actually finish.</div>

<div><br></div><div>So that&#39;s really my only question - how do I make my server completely stop when I&#39;m done? Pointing me towards documentation would be perfectly fine, preferably with a hint about which function(s) I should look at.</div>

<div><br></div><div>TIA</div><div>Wayne</div>