Home > Archive > Ruby > August 2005 > Thread.list confusion
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Thread.list confusion
|
|
| Andrew S. Townley 2005-08-29, 7:02 pm |
|
Still in pursuit of trying to figure out what is going on with my
threads...
Have done the following:
3 class Thread
4 alias __old_initialize initialize
5
6 def initialize(*args, &block)
7 __old_initialize(*args, &block)
8 STDERR.puts "created thread: #{inspect}"
9 STDERR.puts block.to_s
10 end
11 end
This is above any require 'blah' statements so, this should ensure that
any threads created use my hacked version, right?
Maybe I *really* don't understand what's happening here (highly likely),
but my assumption is that I should have an equal number of threads going
through my code as appear in the Thread.list. However, based on my
current numbers, I have 13 calls to my initialize (one of these is from
drb, so it must be doing what I think). However, the Thread list
contains 33 entries (32 sleeping & 1 running).
I've tried various instrumentation stuff, including things like:
#set_trace_func proc { |event, file, line, id, binding, classname|
# if classname.to_s =~ /read/
# printf("%-10s %10s:%-2d %10s %8s\n", event, file, line, id, classname)
# STDOUT.flush
# end
#}
But, I really can't figure out what is happening. From what my code is
doing, I would expect there to be 13 threads created (counting the main
thread). This perfectly matches up with the number of calls to my
hacked Thread class. Anyone have any ideas?
Also, I've looked at this from a number of different angles, but it
appears to be no way to create a normal thread pool with Ruby. Is this
really correct? I found something about this on www.rubygarden.org, but
this isn't exactly what I want (but it is similar in spirit). From
experimentation, it seems that you get one shot for Thread.new. This
seems a bit expensive, but maybe that's just the way it is.
Thanks in advance,
ast
****************************************
****************************************
*******************
The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distri
bution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachme
nts, and any copies thereof from your system.
****************************************
****************************************
*******************
| |
| Eric Hodel 2005-08-29, 7:02 pm |
| On 29 Aug 2005, at 08:57, Andrew S. Townley wrote:
> Still in pursuit of trying to figure out what is going on with my
> threads...
>
> Have done the following:
>
> 3 class Thread
> 4 alias __old_initialize initialize
> 5
> 6 def initialize(*args, &block)
> 7 __old_initialize(*args, &block)
> 8 STDERR.puts "created thread: #{inspect}"
> 9 STDERR.puts block.to_s
> 10 end
> 11 end
>
> This is above any require 'blah' statements so, this should ensure
> that
> any threads created use my hacked version, right?
Yes
> Maybe I *really* don't understand what's happening here (highly
> likely),
> but my assumption is that I should have an equal number of threads
> going
> through my code as appear in the Thread.list. However, based on my
> current numbers, I have 13 calls to my initialize (one of these is
> from
> drb, so it must be doing what I think). However, the Thread list
> contains 33 entries (32 sleeping & 1 running).
ThreadGroup, ThreadGroup, ThreadGroup. Create a ThreadGroup for each
thread you spawn so you can see who is spawning the extra threads.
DRb spawns a thread per connection. To see DRb's threads, do:
drb = DRb.start_service
drb.instance_variable_get('@grp').list
> Also, I've looked at this from a number of different angles, but it
> appears to be no way to create a normal thread pool with Ruby. Is
> this
> really correct? I found something about this on
> www.rubygarden.org, but
> this isn't exactly what I want (but it is similar in spirit). From
> experimentation, it seems that you get one shot for Thread.new. This
> seems a bit expensive, but maybe that's just the way it is.
What do you want?
--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
|
|
|
|
|