[issue35118] Add peek() or first() method in queue

2021-03-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: >> FWIW, the standard library queue module doesn't have >> a straight-forward way to implement a peek() method. > I currently use `q.deque[0]` The Queue class is only allowed to call _init, _qsize, _put, and _get. It is not allowed to directly touch the

[issue35118] Add peek() or first() method in queue

2021-03-16 Thread Alexey Volkov
Alexey Volkov added the comment: >Why not just dismiss older queue entries during a normal get() operation? Or >just use a plain deque with access guarded by a lock. You do not know whether the item needs to be removed until you see it. And to see it you need to get it. And if you get it, y

[issue35118] Add peek() or first() method in queue

2021-03-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: > I want to examine the first (oldest) element in queue and > remove it if it's too old. Why not just dismiss older queue entries during a normal get() operation? Or just use a plain deque with access guarded by a lock. FWIW, the standard library queue

[issue35118] Add peek() or first() method in queue

2021-03-05 Thread Alexey Volkov
Alexey Volkov added the comment: >For Queue, I'm not sure I've ever seen any use case for peek. What do you >have in mind? I want to examine the first (oldest) element in queue and remove it if it's too old. The queue should not be modified unless the oldest element is too old. --

[issue35118] Add peek() or first() method in queue

2018-11-04 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue35118] Add peek() or first() method in queue

2018-11-04 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 98b85354153883b0a080f678f213729cd0764fee by Raymond Hettinger (Windson yang) in branch 'master': bpo-35118: Improve docs regarding indexing (GH-10265) https://github.com/python/cpython/commit/98b85354153883b0a080f678f213729cd0764fee ---

[issue35118] Add peek() or first() method in queue

2018-10-31 Thread Windson Yang
Change by Windson Yang : -- keywords: +patch pull_requests: +9576 stage: -> patch review ___ Python tracker ___ ___ Python-bugs-lis

[issue35118] Add peek() or first() method in queue

2018-10-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: In the absence of good use cases, I'll decline the API expansion. Feel free to post a PR to have the deque documentation to mention d[0] indexing more prominently. Am not really sure that is needed though, we don't have to point out the same thing for li

[issue35118] Add peek() or first() method in queue

2018-10-30 Thread Windson Yang
Windson Yang added the comment: For deque, we can add peek() function to deque or just make it clear in the document that we can use deque[0] to access the first element(I can only find index method in the document) For Queue, I found Java and C++ has the function like first() or peek(), I'm

[issue35118] Add peek() or first() method in queue

2018-10-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: For deque, we have d[0]. Is anything more needed? Even lists don't require a peek. For Queue, I'm not sure I've ever seen any use case for peek. What do you have in mind? * https://docs.oracle.com/javase/7/docs/api/java/util/Queue.html#peek() -

[issue35118] Add peek() or first() method in queue

2018-10-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: docs@python -> rhettinger nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list m

[issue35118] Add peek() or first() method in queue

2018-10-30 Thread Windson Yang
New submission from Windson Yang : I found other languages like Java and C++ have the method to access the first value in Queue like first() and peek(). Since we use deque_ to create Queue now, it's easy to implement in python using the index. Otherwise, we can add this to the document? I als