mirror of
				https://github.com/jlu5/PyLink.git
				synced 2025-10-31 06:57:21 +01:00 
			
		
		
		
	Irc: block when the queue is empty instead of needlessly polling it
Rework Irc.processQueue() to block when the queue is full, and abort if the item "None" is sent to it. To make sure that the None isn't caught by a full queue or pushed back by other elements, this modifies queue.Queue's underlying deque instance directly. Closes #459.
This commit is contained in:
		
							parent
							
								
									06d49f4433
								
							
						
					
					
						commit
						daa6593534
					
				
							
								
								
									
										18
									
								
								classes.py
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								classes.py
									
									
									
									
									
								
							| @ -179,14 +179,12 @@ class Irc(utils.DeprecatedAttributesObject): | ||||
|         while True: | ||||
|             throttle_time = self.serverdata.get('throttle_time', 0.005) | ||||
|             if not self.aborted.wait(throttle_time): | ||||
|                 try: | ||||
|                     data = self.queue.get_nowait() | ||||
|                 data = self.queue.get() | ||||
|                 if data is None: | ||||
|                     log.debug('(%s) Stopping queue thread due to getting None as item', self.name) | ||||
|                     break | ||||
|                 elif data: | ||||
|                     self._send(data) | ||||
|                 except queue.Empty: | ||||
|                     pass | ||||
|             else: | ||||
|                 log.debug('(%s) Stopping queue thread as aborted is set', self.name) | ||||
|                 break | ||||
| 
 | ||||
|     def connect(self): | ||||
|         """ | ||||
| @ -396,6 +394,12 @@ class Irc(utils.DeprecatedAttributesObject): | ||||
| 
 | ||||
|         self.socket.close() | ||||
| 
 | ||||
|         # Stop the queue thread. | ||||
|         if self.queue: | ||||
|             # XXX: queue.Queue.queue isn't actually documented, so this is probably not reliable in the long run. | ||||
|             self.queue.queue.appendleft(None) | ||||
| 
 | ||||
|         # Stop the ping timer. | ||||
|         if self.pingTimer: | ||||
|             log.debug('(%s) Canceling pingTimer at %s due to disconnect() call', self.name, time.time()) | ||||
|             self.pingTimer.cancel() | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 James Lu
						James Lu