- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
gh-96471: Add queue shutdown #96474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
    
  
     Closed
                    gh-96471: Add queue shutdown #96474
Changes from 6 commits
      Commits
    
    
            Show all changes
          
          
            14 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      4fd0640
              
                Add threading implementation of queue shutdown
              
              
                EpicWink d942c9e
              
                Fix up implementation, add unit-tests
              
              
                EpicWink f552ac1
              
                Implement for asyncio queues
              
              
                EpicWink 78671f9
              
                WIP: multiprocessing queue shutdown
              
              
                EpicWink 5f31f8e
              
                WIP: multiprocessing queue shutdown
              
              
                EpicWink a2035a6
              
                Merge branch 'main' into queue-shutdown
              
              
                arhadthedev 978b8d1
              
                Replace try-catch with assert-raises ctx-mgrs
              
              
                EpicWink b19f529
              
                WIP: multiprocessing queue shut-down method
              
              
                EpicWink 6d3b3a5
              
                Use enum for asyncio queue shutdown state
              
              
                EpicWink 85827f1
              
                Make asyncio queue state private
              
              
                EpicWink 121de12
              
                Replace try-catch with assert-raises ctx-mgrs
              
              
                EpicWink 5e2df02
              
                Add asyncio queue tests
              
              
                EpicWink 14c53d7
              
                Release joined awaitables
              
              
                EpicWink da10d9f
              
                Zero unfinished tasks
              
              
                EpicWink File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,11 @@ | ||||||
| __all__ = ('Queue', 'PriorityQueue', 'LifoQueue', 'QueueFull', 'QueueEmpty') | ||||||
| __all__ = ( | ||||||
| 'Queue', | ||||||
| 'PriorityQueue', | ||||||
| 'LifoQueue', | ||||||
| 'QueueFull', | ||||||
| 'QueueEmpty', | ||||||
| 'QueueShutDown', | ||||||
| ) | ||||||
|  | ||||||
| import collections | ||||||
| import heapq | ||||||
|  | @@ -18,6 +25,16 @@ class QueueFull(Exception): | |||||
| pass | ||||||
|  | ||||||
|  | ||||||
| class QueueShutDown(Exception): | ||||||
| """Raised when putting on to or getting from a shut-down Queue.""" | ||||||
| pass | ||||||
|  | ||||||
|  | ||||||
| _queue_alive = "alive" | ||||||
| _queue_shutdown = "shutdown" | ||||||
| _queue_shutdown_immediate = "shutdown-immediate" | ||||||
|  | ||||||
|  | ||||||
| class Queue(mixins._LoopBoundMixin): | ||||||
| """A queue, useful for coordinating producer and consumer coroutines. | ||||||
|  | ||||||
|  | @@ -41,6 +58,7 @@ def __init__(self, maxsize=0): | |||||
| self._finished = locks.Event() | ||||||
| self._finished.set() | ||||||
| self._init(maxsize) | ||||||
| self.shutdown_state = _queue_alive | ||||||
|         
                  EpicWink marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||||||
|  | ||||||
| # These three are overridable in subclasses. | ||||||
|  | ||||||
|  | @@ -113,6 +131,8 @@ async def put(self, item): | |||||
| Put an item into the queue. If the queue is full, wait until a free | ||||||
| slot is available before adding item. | ||||||
| """ | ||||||
| if self.shutdown_state != _queue_alive: | ||||||
|          | ||||||
| if self.shutdown_state != _queue_alive: | |
| if self.shutdown_state is not _QueueState.ALIVE: | 
        
          
              
                  EpicWink marked this conversation as resolved.
              
          
            Show resolved
            Hide resolved
        
      
                  EpicWink marked this conversation as resolved.
              
          
            Show resolved
            Hide resolved
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.