How to do Python stuff in multiple threads

#!/bin/python

 

import threading

import time

import socket

 

host = “192.168.1.104″

 

#this is what is done in each thread, use global variables (defined above here) to pass params

class MyThread ( threading.Thread ):

 

def run ( self ):

sock = socket.socket()

port = 80

sock.connect((host,port))        #connect directly

sock.send(“CONNECT “+host+”:80 HTTP/1.0\r\n\r\n”)

#      print sock.recv(1024)

sock.close

 

timeA = time.time()

 

#this is where I start 100 threads

for x in xrange ( 1000 ):

MyThread().start()

 

timeB = time.time()

 

#this runs it in a single thread, for comparison

#for x in xrange ( 1000 ):

#      sock = socket.socket()

#      port = 80

#      sock.connect((host,port))        #connect directly

#      sock.send(“GET “+host+”:80 HTTP/1.0\r\n\r\n”)

#      print sock.recv(1024)

#      sock.close

#timeC = time.time()

 

print “————————————————————————”

print “started at: “+str(timeA)

print “threaded run stopped, and single thread started: “+str(timeB)

#print “single thread done: “+str(timeC)

print “————————————————————————”