Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling recv hangs after handle is called
    text
    copied!<p>I've got a Python class I'm using to emulate an IMAP server for a unit test. When the <code>handle()</code> callback happens, I try to use <code>recv()</code> to get the data that just arrived but I'm blocking on the <code>recv()</code> call. I thought <code>recv()</code> would return with the data that was received but instead, it just sits there.</p> <p>In case it matters, I can see that the server and main thread are different in the log output.</p> <p>I'm assuming that this has something to do with the fact that the socket was just opened but no data was sent through it. Do I need to check to see if that's the case before trying to call <code>recv()</code>?</p> <p>I've created the server using:</p> <pre><code>class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass ... # inside another class, we've got: def startUp(self): server = ThreadedTCPServer(('localhost', 5593), FakeImapServerHandler) server.allow_reuse_address = True server_thread = threading.Thread(target=server.serve_forever) server_thread.setDaemon(True) server_thread.start() </code></pre> <p>Then inside some other code in our unit test, we try to connect to the fake server:</p> <pre><code> print("about to connect") self.__imapCon = imaplib.IMAP4("localhost", 5593) print("about to login") # we never get here self.__imapCon.login(Config.config["imapUser"], Config.config["imapPassw"]) </code></pre> <p>The server is implemented like:</p> <pre><code>class FakeImapServerHandler(SocketServer.BaseRequestHandler): def handle(self): print("handling request") incoming = self.request.recv(1024) print("request was: " + incoming ) # never get here </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload