Skip to content

Instantly share code, notes, and snippets.

@sanfx
Created August 8, 2014 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanfx/473c34afe51df66bb495 to your computer and use it in GitHub Desktop.
Save sanfx/473c34afe51df66bb495 to your computer and use it in GitHub Desktop.
import threading
def f(arg):
global running
running += 1
print("Spawned a thread. running=%s, arg=%s" % (running, arg))
for i in range(100000):
pass
running -= 1
print("Done")
running = 0
while True:
if running < 8:
arg = get_task()
threading.Thread(target=f, args=[arg]).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment