mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-09-04 00:01:02 -04:00
hackernews script: running in separate thread now to make backtracing easier
This commit is contained in:
parent
ec17795dbe
commit
d02e328077
@ -1,21 +1,39 @@
|
||||
require "httpx"
|
||||
require "oga"
|
||||
|
||||
frontpage = HTTPX.get("https://news.ycombinator.com").to_s
|
||||
|
||||
html = Oga.parse_html(frontpage)
|
||||
|
||||
links = html.css('.itemlist a.storylink').map{|link| link.get('href') }
|
||||
|
||||
links = links.select {|l| l.start_with?("https") }
|
||||
|
||||
puts links
|
||||
|
||||
responses = HTTPX.get(*links)
|
||||
|
||||
links.each_with_index do |l, i|
|
||||
puts "#{responses[i].status}: #{l}"
|
||||
def print_status
|
||||
# thread backtraces
|
||||
Thread.list.each do |th|
|
||||
# next if th == Thread.current
|
||||
id = th.object_id
|
||||
puts "THREAD ID: #{id}"
|
||||
th.backtrace.each do |line|
|
||||
puts "\t#{id}: " + line
|
||||
end if th.backtrace
|
||||
puts "#" * 20
|
||||
end
|
||||
end
|
||||
|
||||
Signal.trap("INFO") { print_status } unless ENV.key?("CI")
|
||||
|
||||
Thread.start do
|
||||
frontpage = HTTPX.get("https://news.ycombinator.com").to_s
|
||||
|
||||
html = Oga.parse_html(frontpage)
|
||||
|
||||
links = html.css('.itemlist a.storylink').map{|link| link.get('href') }
|
||||
|
||||
links = links.select {|l| l.start_with?("https") }
|
||||
|
||||
puts links
|
||||
|
||||
responses = HTTPX.get(*links)
|
||||
|
||||
links.each_with_index do |l, i|
|
||||
puts "#{responses[i].status}: #{l}"
|
||||
end
|
||||
end.join
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user