摘要: 示例代码如下: import threading import time from concurrent.futures import ThreadPoolExecutor def make_food(food): print(food, "开始制作") time.sleep(2) print(fo 阅读全文
posted @ 2021-03-26 16:55 程序员陈师兄cxycsx 阅读(1048) 评论(0) 推荐(0)
摘要: 示例代码如下: import threading import time from concurrent.futures import ThreadPoolExecutor def make_food(food): print(food, "开始制作") time.sleep(2) print(fo 阅读全文
posted @ 2021-03-26 16:39 程序员陈师兄cxycsx 阅读(47) 评论(0) 推荐(0)
摘要: 线程锁,示例代码如下: import threading import time total = 0 def add(lock): global total for i in range(100000): lock.acquire() total += 1 lock.release() def mi 阅读全文
posted @ 2021-03-26 16:23 程序员陈师兄cxycsx 阅读(271) 评论(0) 推荐(0)
摘要: 示例代码如下: import threading import time total = 0 def add(): global total for i in range(100000): total += 1 print(total) def minus(): global total for i 阅读全文
posted @ 2021-03-26 16:18 程序员陈师兄cxycsx 阅读(112) 评论(0) 推荐(0)
摘要: 示例代码如下: import threading import time class Task(threading.Thread): def __init__(self, food, finish_food): super().__init__() self.food = food self.fin 阅读全文
posted @ 2021-03-26 15:55 程序员陈师兄cxycsx 阅读(46) 评论(0) 推荐(0)
摘要: 示例代码如下: import threading import time class Task(threading.Thread): def __init__(self, food): super().__init__() self.food = food def run(self): print( 阅读全文
posted @ 2021-03-26 15:43 程序员陈师兄cxycsx 阅读(97) 评论(0) 推荐(0)
摘要: 快捷方式 ctrl + alt + l 阅读全文
posted @ 2021-03-26 15:13 程序员陈师兄cxycsx 阅读(94) 评论(0) 推荐(0)
摘要: 示例代码如下: import threading import time class Task(threading.Thread): def __init__(self, food): super().__init__() self.food = food def run(self): print( 阅读全文
posted @ 2021-03-26 15:10 程序员陈师兄cxycsx 阅读(42) 评论(0) 推荐(0)
摘要: 示例代码如下: import threading import time def make_food(food): print(food, "开始制作") time.sleep(2) print(food, "制作完成") def main(): food_list = ['番茄炒鸡蛋', '青椒炒 阅读全文
posted @ 2021-03-26 14:56 程序员陈师兄cxycsx 阅读(41) 评论(0) 推荐(0)
摘要: 由于GIL锁的限制,多核CPU无法并行执行同一进程内的多个线程 在一个进程内,同一时刻只能有一个线程通过获取GIL锁被CPU调度 阅读全文
posted @ 2021-03-26 14:44 程序员陈师兄cxycsx 阅读(48) 评论(0) 推荐(0)