Skip to content

Instantly share code, notes, and snippets.

@leadscloud
Created February 22, 2021 06:46
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 leadscloud/e31bb661d6760220cd29ff2479224c20 to your computer and use it in GitHub Desktop.
Save leadscloud/e31bb661d6760220cd29ff2479224c20 to your computer and use it in GitHub Desktop.
python thread多线程
import threading
import time
thread_num = 0
lock = threading.Lock()
def do_request():
global thread_num
# -------------
# my code here
# -------------
with lock:
thread_num -= 1
while True:
if thread_num <= 50:
with lock:
thread_num += 1
t = threading.Thread(target=do_request)
t.start()
else:
time.sleep(0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment