[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: newbie question regarding threads and system commands

Edwin Fine

11/25/2006 5:43:00 AM

This is one possible solution, which seems to work fine (it takes 3.14
seconds on my system to ping 3 web sites). Bottom line: you need to keep
a list of the threads and join all of them in the calling code. Hope
this helps. I recommend that you get a copy of the "Pickaxe" book
(Programming Ruby: The Pragmatic Programmers Guide, 2nd edition) , which
has a very good section on threading and lots of examples. In the
meantime, you can read this from the first edition:

http://www.rubycentral.com/book/tut_th...
-------------
require 'thread'

class SystemExecutor
# Returns array [[cmd, response], [cmd, response], ...]
def SystemExecutor.run(system_cmd_list)
thread_list = []
system_response_list = []
srl_mutex = Mutex.new

system_cmd_list.each do |cmd|
thread_list << Thread.new do
begin
response = %x{ #{cmd} }
srl_mutex.synchronize do
system_response_list << [cmd, response]
end
rescue Exception => exc
srl_mutex.synchronize do
system_response_list << [cmd, exc]
end
end
end
end

thread_list.each { |thr| thr.join }
system_response_list
end
end

puts "Starting ping"
start_time = Time.now
resp = SystemExecutor.run(['ping www.ruby-forum.org', 'ping
www.sourceforge.net', 'ping www.google.com'])
elapsed_time = Time.now - start_time

resp.each do |cmd, resp|
puts "Command: #{cmd}", '-' * 20
puts "Response:\n", '-' * 20, "#{resp}"
end

puts "Elapsed time: #{elapsed_time} seconds."

--
Posted via http://www.ruby-....

1 Answer

tkraju via OfficeKB.com

4/7/2009 12:58:00 PM

0

Thank you Joel,
I learned a new thing,I used Cells(j,"B")=Int(Now) ,it gave me desired
results.
Thanks once again.
joel wrote:
>I see two problems with your posting
>
>1) the dfgference between now() and today is now includes hours and minutes
>while today(0 is set at midnight of the date. Time is a number with days the
>whole part of the number and hours and minutes are the fractional part.
>April, 7, 2009 = 39910. 8 AM is 8hours/24 hours = .3333333
>
>So today() = 39910 and Now() = 39910.3333333333
>
>Using the INT function will make them equivalent
>
>Today() = Int(Now())
>
>2) A text box returns TEXT not a Date. You need to use the
>DATEVALUE("4/1/09") function to convert the text string to a number.
>DateValue will take any format string the excel recognizes "4/1/09",
>"4/1/2009", "April 1, 2009"). the only problem with datevalue is the
>internation standards wherre US has month 1st and England uses Day 1st.
>
>from:
>If Cells(j,"A")=Me.TextBox1.Text
>to:
>If Cells(j,"A")=DateValue(Me.TextBox1.Text)
>
>> I have w/sheet cell B1= Now(),i.e date with time.
>> what vba code should I use whether B1=today's date or not.
>> I use :- If Cells(j,"A")=Me.TextBox1.Text And Cells(j,"B")=today
>> its not giving me desired results.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/excel-programmin...