Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. import re
  2. import time
  3. import subprocess
  4.  
  5. hosts = []
  6. threads = {}
  7. tmpKill = []
  8.  
  9. eMailList = []
  10.  
  11. running = 1
  12. currentEmail = 1
  13. finished = 0
  14.  
  15. f = open('output', 'a')
  16.  
  17. def cleanupThreads():
  18.     for host in threads:
  19.         if time.time() - threads[host][1] > 5:
  20.             tmpKill.append(host)
  21.     killThreads()
  22.  
  23. def killThreads():
  24.     for host in tmpKill:
  25.         if host in threads:
  26.             threads[host][0].kill()
  27.             del threads[host]
  28.             f.write(host)
  29.             f.write('\n')
  30.     for host in tmpKill:
  31.         del tmpKill[tmpKill.index(host)]
  32.  
  33. def addNextThread():
  34.     global currentEmail
  35.     thisHost = eMailList[currentEmail]
  36.     f.write(thisHost)
  37.     f.write('\n')
  38.     threads[thisHost[0]] = [subprocess.Popen(['python', 'newEmail.py', thisHost], shell=False), time.time()]
  39.     currentEmail += 1
  40.     #print currentEmail
  41.  
  42. fileHandle = open('list.txt', "r")
  43. for line in fileHandle:
  44.      line = line.rstrip('\n')
  45.      eMailList.append(line)
  46.  
  47. print eMailList
  48.  
  49. print "Total emails: %d" % len(eMailList)
  50.  
  51. while running:
  52.     if len(threads) >= 10:
  53.         cleanupThreads()
  54.     else:
  55.         if finished:
  56.             #closeCleanup()
  57.             print "### FINISHED ###"
  58.             running = 0
  59.         else:
  60.             addNextThread()
  61.     if currentEmail >= len(eMailList) - 1:
  62.         print "Cleaning up!"
  63.         print "-"
  64.         print "-"
  65.         finished = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement