随笔分类 - Python日常学习
摘要:进程池 p = Pool(5) p.apply 每个任务是排队进行。进程.join() # 等待 p.apply_async 每一个任务都并发执行可设置回调函数,进程.无join();进程daemon=True # 不等待
阅读全文
摘要:1 import queue 2 import threading 3 4 q = queue.Queue(10) 5 def product(i): 6 print('put:'+ str(i)) 7 q.put(i) 8 9 def customer(i): 10 msg = q.get() 11 print(msg) 12 13 fo...
阅读全文
摘要:import threadingimport timenum = 0lock = threading.RLock()def fun(): lock.acquire() global num num+=1 time.sleep(1) print(num) lock.release()for i in
阅读全文
摘要:1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 import socket 4 sk1 = socket.socket() 5 sk1.bind(('127.0.0.1',8001,)) 6 sk1.listen() 7 8 inputs = [sk1,] 9 outputs = [] 10 message_dict = ...
阅读全文
摘要:1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 import socketserver 4 class mysever(socketserver.BaseRequestHandler): 5 def handle(self): 6 conn = self.request 7 # 和之前创建...
阅读全文
摘要:一、服务端 二、客户端 三、服务端传输文件 四、客户端发送文件
阅读全文
摘要:单例模式只有一个实例 静态方法+静态字段 所有的实例中封装的内容相同时,用单利模式 ` from wsgiref.simple_server import make_server def Runsever(environ,start_response): start_response(status
阅读全文
摘要:1 class foo: 2 def __init__(self): 3 print('init') 4 def __call__(self, *args, **kwargs): 5 print('call') 6 return 1 7 def __getitem__(self, item): 8 ...
阅读全文
摘要:resul: B的构造方法A的构造方法{'n': '猫', 'ty': '动物'}
阅读全文
摘要:interface :起到约束作用,我有几个方法,在继承之后必须实现我的方法
阅读全文
摘要:1 class foo: 2 def f1(self): 3 print('f1') 4 5 class bar: 6 def f1(self): 7 print('f1') 8 9 def func(args): 10 args.f1() 11 12 func(foo()) 13 func(bar())
阅读全文
摘要:1 class person: 2 def __init__(self,name,age,weight): 3 self.Name = name 4 self.Age = age 5 self.Weight = weight 6 def chi(self): 7 self.Weight+=2 8 ...
阅读全文
摘要:类的实例oldb ==>方法内self,并作为形式参数传递给方法
阅读全文

浙公网安备 33010602011771号