Member Avatar for sravan953

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!

Recommended Answers

All 2 Replies

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.