摘要: import time import random from threading import Thread,Event def conn_db(e): count = 0 while count < 3: e.wait(1) if e.is_set(): print("连接数据库成功") brea 阅读全文
posted @ 2018-12-16 15:55 superniao 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 守护进程随着主进程的代码的执行结束而结束 守护线程会在主线程结束之后等待其他子线程的结束才结束(如有其他子线程,没有其他子线程就是主线程结束守护线程随之结束) 主进程在执行玩完自己的代码后不会立即结束,而是等待子进程结束之后,回收子进程的资源 阅读全文
posted @ 2018-12-16 13:59 superniao 阅读(366) 评论(0) 推荐(0) 编辑
摘要: import time from threading import Thread def func(n): #time.sleep(1) print(n) for i in range(10): t = Thread(target=func,args=(i,)) t.start() import t 阅读全文
posted @ 2018-12-16 13:51 superniao 阅读(85) 评论(0) 推荐(0) 编辑
摘要: from multiprocessing import Process,Manager,Lock def func(dic,lock): lock.acquire() dic["count"] -= 1 lock.release() if __name__ == '__main__': m = Ma 阅读全文
posted @ 2018-12-15 18:19 superniao 阅读(150) 评论(0) 推荐(0) 编辑
摘要: import time import random from multiprocessing import Process,Queue def producer(q,name,food): for i in range(4): time.sleep(random.random()) f = "{}生 阅读全文
posted @ 2018-12-15 13:52 superniao 阅读(207) 评论(0) 推荐(0) 编辑
摘要: import time,json from multiprocessing import Process,Lock def show(i): with open("ticket") as f: dic = json.load(f) print("余票:{}".format(dic["ticket"])) time.sleep(0.1) ... 阅读全文
posted @ 2018-12-15 13:51 superniao 阅读(318) 评论(0) 推荐(0) 编辑
摘要: import time,random from multiprocessing import Process,Semaphore def ktv(i,sem): sem.acquire() print("{} come in horse".format(i)) time.sleep(random.randint(1,5)) print("{} go out hor... 阅读全文
posted @ 2018-12-15 13:50 superniao 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 一个信号可以使所有的进程进入阻塞状态,也是解除所有阻塞。一个事件被创建后,默认阻塞状态 阅读全文
posted @ 2018-12-14 21:34 superniao 阅读(308) 评论(0) 推荐(0) 编辑
摘要: 第一种:创建Process对象 第二种:创建自定义类并继承Process类,必须实现run方法,进程启动自动调用run方法 阅读全文
posted @ 2018-12-12 21:27 superniao 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 基本语法: chown [-R] 账号名称 文件或目录 chown [-R] 账号名称:用户组名称 文件或目录基本语法: chgrp [-R] 用户组名称 dirname/filename ... -R是递归 修改的同时也修改该目录下所有文件和目录 drwxr-xr-x. 3 root root 1 阅读全文
posted @ 2018-12-11 10:18 superniao 阅读(900) 评论(0) 推荐(0) 编辑