[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 underlying data structure.  Otherwise, 
subclasses relying on the abstraction would fail.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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, you cannot push it back to the 
start of the queue.

>FWIW, the standard library queue module doesn't have a straight-forward way to 
>implement a peek() method.

I currently use `q.deque[0]`

>Or just use a plain deque with access guarded by a lock.

I can. But technically the same applies to almost any queue usage.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 module doesn't have a straight-forward way to 
implement a peek() method.  The module guarantees that the underlying data 
structure is only accessed with _init, _qsize, _get, and _put.


That would be difficult to do atomically with a Queue object.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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.

--
nosy: +Ark-kun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 lists and I haven't encountered any 
misunderstandings on the topic.  This would be just a minor usage note.

--
priority: normal -> low

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 
not sure should we also implement a method like this.


* http://www.cplusplus.com/reference/queue/queue/

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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()

--
versions:  -Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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 also found some discussion_ here.


.. _deque: 
 https://github.com/python/cpython/blob/master/Lib/queue.py#L205

.. _discussion 
https://mail.python.org/pipermail/python-list/2010-March/569930.html

--
assignee: docs@python
components: Documentation
messages: 328963
nosy: Windson Yang, docs@python
priority: normal
severity: normal
status: open
title: Add peek() or first() method in queue
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com