Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the done method of the WorkQueue
Previously, keys were always removed from the active set when the done method was called. When a key was present in the dirty dictionary, the key was added to the queue, but not to the active set. When a certain sequence of actions were happening, this lead to the key being present in the queue, but not in the dirty dictionary, subsequently raising a KeyError: # 'dirty': {} # 'active': set(), # 'queue': <Queue at 0x7f8c75c50208 maxsize=0> await queue.put("key", 1) # 'dirty': {'key': 1} # 'active': {'key'}, # 'queue': <Queue at 0x7f8c75c50208 maxsize=0 _queue=['key'] tasks=1> await queue.get() # 'dirty': {} # 'active': {'key'}, # 'queue': <Queue at 0x7f8c75c50208 maxsize=0 tasks=1> await queue.put("key", 2) # 'dirty': {'key': 2} # 'active': {'key'}, # 'queue': <Queue at 0x7f8c75c50208 maxsize=0 tasks=1> await queue.done("key") # 'dirty': {'key': 2} # 'active': set(), # 'queue': <Queue at 0x7f8c75c50208 maxsize=0 _queue=['key'] tasks=2> # => the WorkQueue is in an invalid state with a key in queue which is not # present in active await queue.put("key", 3) # 'dirty': {'key': 3} # 'active': {'key'}, # 'queue': <Queue at 0x7f8c75c50208 maxsize=0 _queue=['key', 'key'] tasks=3> # => the WorkQueue is in an invalid state with the key present two times in the # queue await queue.get() # 'dirty': {} # 'active': {'key'}, # 'queue': <Queue at 0x7f8c75c50208 maxsize=0 _queue=['key'] tasks=3> await queue.done("key") # 'dirty': {} # 'active': set(), # 'queue': <Queue at 0x7f8c75c50208 maxsize=0 _queue=['key'] tasks=3> await queue.get() # Raises KeyError: 'key' This commit fixes this error by only removing the key from the active set if it isn't added to the queue.
- Loading branch information