0

Hey guys...

I have some code here:

import os
import threading
import urllib
import time

a=0

class launch(threading.Thread):
    def start_now():
        try:
            urllib.urlopen("http://www.google.com")
        except:
            a+=1
    start_now()

def end():
    print("\nOut of 10000 requests, "+str(a)+" requests failed.")

for x in range(10001):
    launch().start()
    print("http://www.google.com")

end()
raw_input("<Done>")

This works, in the sense that it goes on and on printing "www.google.com", but the same code a little modified doesn't work:

import os
import threading
import urllib
import time

a=0

class launch(threading.Thread):
    def start_now():
        try:
            print("http://www.google.com")
            urllib.urlopen("http://www.google.com")
        except:
            a+=1
    start_now()

def end():
    print("\nOut of 10000 requests, "+str(a)+" requests failed.")

for x in range(10001):
    launch().start()

end()
raw_input("<Done>")

It only prints "http://www.google.com" once and nothing happens! What's the difference in code I posted?

Thanks guys!

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by woooee
0

Hey, it does nothing because it takes long time to execute 10000 web queries

0

You should state what you are trying to accomplish and perhaps someone will help with that. We are not your personal answering machine. Please don't waste everyone's time.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.