python - asyncore not running handle_read -


I'm just trying to make a simple Asynccore example where there is a socket sender and a receiver is for some reason, Hold_read () is never called on the receiver, so why do not I get 'test' data, anyone know why? This is my first shot asyncore, so it's probably very simple.

  Import asyncore, socket, pdb, random class sender (asyncore.dispatcher): def __init __ (self): asyncore.dispatcher. DID (self): DEF (self): Correct Def readable (self): Wrong DRF handle_write (self): Pass def handle_close (self): self.close () class receiver (asyncore.dispatcher): def __init __ (Self): asyncore.dispatcher .__ init __ (self) self.create_socket (socket.AF_INET, socket.SOCK_STREAM) DR def_connect itself): print ('first connect') def readable (self): returns true def handle_read ): Print 'reading' def handlight (self): print 'right' def handle expedition (self): self.conn_sock, addr = self.accept () print 'approved' def handle Lowe's (self): self. Close () A = Sender () B = Receiver () ADR = ('localhost', 12344) B.Bind (Adr) B. Lliston (1) A. Connect (asr) asyncore.loop () a.send (' Test ')  

asyncore.loop does not end , Therefore a.send does not occur, because you have coded it to be in line after that exits asyncore.loop.

After it is fixed, you run into the problem that you are running the sender and the receiver within a thread and process, so unless you take a very delicate step to make sure that all Some orders are correct, you are going to get deadlocked. Asyncor is used between different processes, so this problem does not appear in normal, real-world uses if you really want to If you are curious about docking, then make a copy of your asyncor and pepper with print statement, or

  Python-M trace-T astapa  

Unfortunately, the latter gives an lot output and does not show significant variable 'value. Therefore, to make a painless and non-invasive effort, few strategically placed print s (e.g., before and after R & W FD lists before and after each selection) It is helpful.

I believe (but have not debug it in depth, because it is an unrealistic scenario, anyway) that selection triggers only once (because you accept / accept both and The writings of bytes are done before the first socket, they "collapse" in the same event), but handling that one event does not know about falling (not in normal use! -) Therefore it only accepts / can But if you take the time to debug more deeply, you will not have any doubt in it!


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -