Python-多线程注意事项
锁申请位置错误导致内存泄露-多线程内存泄露注意事项 # encoding: UTF-8 import threading import time def show_fun(sem, n): # 不能放在这里 # sem_lock.acquire() print("{0}start -- {1}".format(time.ctime(), n)) print "working" time.sleep(2) print("{0}end -- {1}".format(time.ctime(), n)) sem.release() if __name__ == '__main__': max_connections = 5 semaphore = threading.BoundedSemaphore(max_connections)……