def pro(p1,p2): t_name = threading.currentThread().getName() with open('/User/zqh/tmp/test.txt', 'a') as f: fcntl.flock(f.fileno(), fcntl.LOCK_EX) #读写排它锁 print "threan_name%s,value:%s%s" % (t_name,p1,p2) f.write("%s%s \n") % (p1,p2) return "%s=success" % t_name def content(p2): all_tasks = [] thread_executor = ThreadPoolExecutor(max_workers=5, thread_name_prefix="dqc-crontab-data") lst = [1,2,3,4,5,6,7,8,9,10] for i in lst: all_tasks.append(thread_executor.submit(pro, str(i), str(p2))) for future in as_completed(all_tasks): future_result = future.result() print 'future_result>>%s;' % future_result thread_executor.shutdown()
Python 标准库之 fcntl
最新推荐文章于 2024-08-09 17:06:24 发布