* [ruby-core:58545] [ruby-trunk - Feature #9145][Open] Queue#pop(true) return nil if empty instead of raising ThreadError
@ 2013-11-24 3:42 jsc (Justin Collins)
2013-11-24 4:30 ` [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] " Glass_saga (Masaki Matsushita)
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: jsc (Justin Collins) @ 2013-11-24 3:42 UTC (permalink / raw)
To: ruby-core
Issue #9145 has been reported by jsc (Justin Collins).
----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145
Author: jsc (Justin Collins)
Status: Open
Priority: Normal
Assignee:
Category: lib
Target version:
I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.
Current behavior is to raise a ThreadError, with a message indicating the queue is empty.
For example:
q = Queue.new
begin
loop do
next_item = q.pop(true)
end
rescue ThreadError
# queue is empty...or maybe something bad happened
end
Instead, this could be
q = Queue.new
while next_item = q.pop(true)
end
Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] Queue#pop(true) return nil if empty instead of raising ThreadError
2013-11-24 3:42 [ruby-core:58545] [ruby-trunk - Feature #9145][Open] Queue#pop(true) return nil if empty instead of raising ThreadError jsc (Justin Collins)
@ 2013-11-24 4:30 ` Glass_saga (Masaki Matsushita)
2013-11-24 4:42 ` [ruby-core:58547] " Eric Wong
2013-11-25 2:55 ` [ruby-core:58562] " Joel VanderWerf
2013-11-25 0:13 ` [ruby-core:58556] [ruby-trunk - Feature #9145] " jsc (Justin Collins)
` (3 subsequent siblings)
4 siblings, 2 replies; 9+ messages in thread
From: Glass_saga (Masaki Matsushita) @ 2013-11-24 4:30 UTC (permalink / raw)
To: ruby-core
Issue #9145 has been updated by Glass_saga (Masaki Matsushita).
Category changed from lib to ext
Status changed from Open to Feedback
I think we can't change default behavior of Queue#pop(true) because some code expects ThreadError to be raised.
However, it may be possible to introduce new keyword argument like following:
q = Queue.new
while next_item = q.pop(true, exception: false) # it doesn't raise ThreadError and returns nil.
# do something
end
----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145#change-43126
Author: jsc (Justin Collins)
Status: Feedback
Priority: Normal
Assignee:
Category: ext
Target version:
I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.
Current behavior is to raise a ThreadError, with a message indicating the queue is empty.
For example:
q = Queue.new
begin
loop do
next_item = q.pop(true)
end
rescue ThreadError
# queue is empty...or maybe something bad happened
end
Instead, this could be
q = Queue.new
while next_item = q.pop(true)
end
Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:58547] Re: [ruby-trunk - Feature #9145][Feedback] Queue#pop(true) return nil if empty instead of raising ThreadError
2013-11-24 4:30 ` [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] " Glass_saga (Masaki Matsushita)
@ 2013-11-24 4:42 ` Eric Wong
2013-11-25 2:55 ` [ruby-core:58562] " Joel VanderWerf
1 sibling, 0 replies; 9+ messages in thread
From: Eric Wong @ 2013-11-24 4:42 UTC (permalink / raw)
To: Ruby developers
"Glass_saga (Masaki Matsushita)" <glass.saga@gmail.com> wrote:
> I think we can't change default behavior of Queue#pop(true) because some code expects ThreadError to be raised.
> However, it may be possible to introduce new keyword argument like following:
>
> q = Queue.new
> while next_item = q.pop(true, exception: false) # it doesn't raise ThreadError and returns nil.
> # do something
> end
+1 to that. All non-blocking methods (I/O or not) should support
exception: false to avoid (expensive/noisy-on-$DEBUG=$true) exceptions.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:58556] [ruby-trunk - Feature #9145] Queue#pop(true) return nil if empty instead of raising ThreadError
2013-11-24 3:42 [ruby-core:58545] [ruby-trunk - Feature #9145][Open] Queue#pop(true) return nil if empty instead of raising ThreadError jsc (Justin Collins)
2013-11-24 4:30 ` [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] " Glass_saga (Masaki Matsushita)
@ 2013-11-25 0:13 ` jsc (Justin Collins)
2013-11-25 6:17 ` [ruby-core:58564] " drbrain (Eric Hodel)
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: jsc (Justin Collins) @ 2013-11-25 0:13 UTC (permalink / raw)
To: ruby-core
Issue #9145 has been updated by jsc (Justin Collins).
Glass_saga (Masaki Matsushita) wrote:
> I think we can't change default behavior of Queue#pop(true) because some code expects ThreadError to be raised.
> However, it may be possible to introduce new keyword argument like following:
>
> q = Queue.new
> while next_item = q.pop(true, exception: false) # it doesn't raise ThreadError and returns nil.
> # do something
> end
That would work for me.
----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145#change-43134
Author: jsc (Justin Collins)
Status: Feedback
Priority: Normal
Assignee:
Category: ext
Target version:
I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.
Current behavior is to raise a ThreadError, with a message indicating the queue is empty.
For example:
q = Queue.new
begin
loop do
next_item = q.pop(true)
end
rescue ThreadError
# queue is empty...or maybe something bad happened
end
Instead, this could be
q = Queue.new
while next_item = q.pop(true)
end
Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:58562] Re: [ruby-trunk - Feature #9145][Feedback] Queue#pop(true) return nil if empty instead of raising ThreadError
2013-11-24 4:30 ` [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] " Glass_saga (Masaki Matsushita)
2013-11-24 4:42 ` [ruby-core:58547] " Eric Wong
@ 2013-11-25 2:55 ` Joel VanderWerf
1 sibling, 0 replies; 9+ messages in thread
From: Joel VanderWerf @ 2013-11-25 2:55 UTC (permalink / raw)
To: Ruby developers
On 11/23/2013 08:30 PM, Glass_saga (Masaki Matsushita) wrote:
> I think we can't change default behavior of Queue#pop(true) because some code expects ThreadError to be raised.
> However, it may be possible to introduce new keyword argument like following:
>
> q = Queue.new
> while next_item = q.pop(true, exception: false) # it doesn't raise ThreadError and returns nil.
> # do something
> end
Or what about a new method, Queue#pop?, which is always non-blocking and
non-raising. It would behave like:
class Queue
def pop?
pop(true)
rescue ThreadError
nil
end
end
q = Queue.new
q << 1
q << 2
q << 3
while x=q.pop?
p x
end
__END__
output:
1
2
3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:58564] [ruby-trunk - Feature #9145] Queue#pop(true) return nil if empty instead of raising ThreadError
2013-11-24 3:42 [ruby-core:58545] [ruby-trunk - Feature #9145][Open] Queue#pop(true) return nil if empty instead of raising ThreadError jsc (Justin Collins)
2013-11-24 4:30 ` [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] " Glass_saga (Masaki Matsushita)
2013-11-25 0:13 ` [ruby-core:58556] [ruby-trunk - Feature #9145] " jsc (Justin Collins)
@ 2013-11-25 6:17 ` drbrain (Eric Hodel)
2017-06-22 7:23 ` [ruby-core:81738] [Ruby trunk Feature#9145][Closed] " glass.saga
2018-01-01 19:41 ` [ruby-core:84576] [Ruby trunk Feature#9145] " uwe
4 siblings, 0 replies; 9+ messages in thread
From: drbrain (Eric Hodel) @ 2013-11-25 6:17 UTC (permalink / raw)
To: ruby-core
Issue #9145 has been updated by drbrain (Eric Hodel).
Note that the current behavior allows you to distinguish between a nil in the queue (returns nil) and no value in the queue (raises ThreadError)
----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145#change-43140
Author: jsc (Justin Collins)
Status: Feedback
Priority: Normal
Assignee:
Category: ext
Target version:
I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.
Current behavior is to raise a ThreadError, with a message indicating the queue is empty.
For example:
q = Queue.new
begin
loop do
next_item = q.pop(true)
end
rescue ThreadError
# queue is empty...or maybe something bad happened
end
Instead, this could be
q = Queue.new
while next_item = q.pop(true)
end
Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.
--
http://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:81738] [Ruby trunk Feature#9145][Closed] Queue#pop(true) return nil if empty instead of raising ThreadError
2013-11-24 3:42 [ruby-core:58545] [ruby-trunk - Feature #9145][Open] Queue#pop(true) return nil if empty instead of raising ThreadError jsc (Justin Collins)
` (2 preceding siblings ...)
2013-11-25 6:17 ` [ruby-core:58564] " drbrain (Eric Hodel)
@ 2017-06-22 7:23 ` glass.saga
2017-06-22 7:44 ` [ruby-core:81739] " Eric Wong
2018-01-01 19:41 ` [ruby-core:84576] [Ruby trunk Feature#9145] " uwe
4 siblings, 1 reply; 9+ messages in thread
From: glass.saga @ 2017-06-22 7:23 UTC (permalink / raw)
To: ruby-core
Issue #9145 has been updated by Glass_saga (Masaki Matsushita).
Status changed from Feedback to Closed
Currently, Queue#pop takes non_block flag.
----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145#change-65440
* Author: jsc (Justin Collins)
* Status: Closed
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.
Current behavior is to raise a ThreadError, with a message indicating the queue is empty.
For example:
q = Queue.new
begin
loop do
next_item = q.pop(true)
end
rescue ThreadError
# queue is empty...or maybe something bad happened
end
Instead, this could be
q = Queue.new
while next_item = q.pop(true)
end
Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:81739] Re: [Ruby trunk Feature#9145][Closed] Queue#pop(true) return nil if empty instead of raising ThreadError
2017-06-22 7:23 ` [ruby-core:81738] [Ruby trunk Feature#9145][Closed] " glass.saga
@ 2017-06-22 7:44 ` Eric Wong
0 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2017-06-22 7:44 UTC (permalink / raw)
To: ruby-core
glass.saga@gmail.com wrote:
> Issue #9145 has been updated by Glass_saga (Masaki Matsushita).
>
> Status changed from Feedback to Closed
>
> Currently, Queue#pop takes non_block flag.
No, I don't think this should be closed.
I think Justin's point was:
Currently, it is impossible to know if a queue is closed
(permanent condition) or if it is empty (temporary condition).
So at the very least, a different exception should be raised:
Justin Collins wrote:
> Alternatively, raise an exception that is a subclass of
> ThreadError with a more specific name, such as "QueueEmpty".
> This would be a small improvement while remaining compatible
> with existing code.
On a side note, relying on exceptions for flow control has all
the same performance and $DEBUG noise problems it did with
IO#*_nonblock [ruby-core:38666] [Feature #5138]
But thinking of an efficient API for that is tricky :<
^ permalink raw reply [flat|nested] 9+ messages in thread
* [ruby-core:84576] [Ruby trunk Feature#9145] Queue#pop(true) return nil if empty instead of raising ThreadError
2013-11-24 3:42 [ruby-core:58545] [ruby-trunk - Feature #9145][Open] Queue#pop(true) return nil if empty instead of raising ThreadError jsc (Justin Collins)
` (3 preceding siblings ...)
2017-06-22 7:23 ` [ruby-core:81738] [Ruby trunk Feature#9145][Closed] " glass.saga
@ 2018-01-01 19:41 ` uwe
4 siblings, 0 replies; 9+ messages in thread
From: uwe @ 2018-01-01 19:41 UTC (permalink / raw)
To: ruby-core
Issue #9145 has been updated by uwe@kubosch.no (Uwe Kubosch).
How about a block form where the block is called with the popped element? The method would return false if called with non_block set to true if the queue is empty.
q = Queue.new
q << 1
q << 2
q << 3
while q.pop(true){|x| p x}
----------------------------------------
Feature #9145: Queue#pop(true) return nil if empty instead of raising ThreadError
https://bugs.ruby-lang.org/issues/9145#change-69116
* Author: jsc (Justin Collins)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I propose the non-blocking form of Queue#pop behave like Array#pop and return nil when empty.
Current behavior is to raise a ThreadError, with a message indicating the queue is empty.
For example:
q = Queue.new
begin
loop do
next_item = q.pop(true)
end
rescue ThreadError
# queue is empty...or maybe something bad happened
end
Instead, this could be
q = Queue.new
while next_item = q.pop(true)
end
Alternatively, raise an exception that is a subclass of ThreadError with a more specific name, such as "QueueEmpty". This would be a small improvement while remaining compatible with existing code.
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-01-01 19:41 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-24 3:42 [ruby-core:58545] [ruby-trunk - Feature #9145][Open] Queue#pop(true) return nil if empty instead of raising ThreadError jsc (Justin Collins)
2013-11-24 4:30 ` [ruby-core:58546] [ruby-trunk - Feature #9145][Feedback] " Glass_saga (Masaki Matsushita)
2013-11-24 4:42 ` [ruby-core:58547] " Eric Wong
2013-11-25 2:55 ` [ruby-core:58562] " Joel VanderWerf
2013-11-25 0:13 ` [ruby-core:58556] [ruby-trunk - Feature #9145] " jsc (Justin Collins)
2013-11-25 6:17 ` [ruby-core:58564] " drbrain (Eric Hodel)
2017-06-22 7:23 ` [ruby-core:81738] [Ruby trunk Feature#9145][Closed] " glass.saga
2017-06-22 7:44 ` [ruby-core:81739] " Eric Wong
2018-01-01 19:41 ` [ruby-core:84576] [Ruby trunk Feature#9145] " uwe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).