pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by frymaster on Mon 18th Oct 00:40
download | new post

  1. #!/usr/bin/python
  3. import subprocess,time,sys,shlex
  4. pollWait=0.01
  5. if len(sys.argv)>1:
  6.   theFilename=sys.argv[1]
  7.   if len(sys.argv)>2:
  8.     try:
  9.       maxNum=int(sys.argv[2])
  10.     except:
  11.       print "ERROR: Second argument should be the number of concurrent processes to run (default 3)"
  12.       sys.exit(1)
  13.   else:
  14.     maxNum=3
  15. else:
  16.   print "Usage:",sys.argv[0],"fileOfCommandsToRun [number to do at once]"
  17.   sys.exit(1)
  18. running=[]
  19. theFile=open(theFilename,"r")
  20. for line in theFile:
  21.   theArgs=shlex.split(line[:-1])
  22.   print "running ",line
  23.   running.append(subprocess.Popen(theArgs))
  24.   while len(running)==maxNum:
  25.     toKill=[]
  26.     for proc in running:
  27.       if proc.poll()!=None:
  28.         toKill.append(proc)
  29.     for proc in toKill:
  30.       running.remove(proc)
  31.     time.sleep(pollWait)
  32. print "(all running, waiting for them to finish)"
  33. while len(running)>0:
  34.     toKill=[]
  35.     for proc in running:
  36.       if proc.poll()!=None:
  37.         toKill.append(proc)
  38.     for proc in toKill:
  39.       running.remove(proc)
  40.     time.sleep(pollWait)
  42. print "All done!"

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@

Remember my settings