11 2018 档案

摘要: 阅读全文
posted @ 2018-11-20 12:34 _Q 阅读(159) 评论(0) 推荐(0) 编辑
摘要:# apply_async: import time from multiprocessing import Pool def fn(i): time.sleep(0.5) return i*i if __name__ == '__main__': p = Pool(5) l = [] for i 阅读全文
posted @ 2018-11-20 12:33 _Q 阅读(896) 评论(0) 推荐(0) 编辑
摘要:""" # apply_async(函数名,args=(参数,),callback=函数名) # callback = 函数名 # 执行完毕后会再次执行一个函数 # 回调函数在 主进程中执行""" from multiprocessing import Pool def fn1(n): print( 阅读全文
posted @ 2018-11-20 12:32 _Q 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-20 12:31 _Q 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-20 12:29 _Q 阅读(99) 评论(0) 推荐(0) 编辑
摘要:""" pipe: -- ( 队列 = 管道 + 锁 ) # 数据不安全 # 可以加锁控制安全性 # 当管道全部关闭 只剩接收管道 时 并且没有 可以send 的内容 的时候会报一个 EOFError 的错误 @ 解决方案: 在处理异常时(try) 将管道(接收管道)全部关闭 # 主进程中的 con 阅读全文
posted @ 2018-11-20 12:00 _Q 阅读(96) 评论(0) 推荐(0) 编辑
摘要:# q = Queue() # 创建队列 # q.put(1) # 向队列中添加数据# print(q.empty()) # 判断队列是否为空 False ( 不准确 -- 当返回结果的途中,可能结果为改变)# print(q.full()) # 判断队列是否满了 False ( 不准确 )# pr 阅读全文
posted @ 2018-11-20 11:54 _Q 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-20 11:52 _Q 阅读(132) 评论(0) 推荐(0) 编辑
摘要:# 一个信号可以使所有的进程都进入阻塞状态 # 也可以控制所有的进程解除阻塞# 一个事件被创建之后,默认使阻塞状态 # set / clear ( True为不阻塞,False为阻塞 ) # 修改事件的状态 True or False # set --> True # clear --> False 阅读全文
posted @ 2018-11-20 11:51 _Q 阅读(164) 评论(0) 推荐(0) 编辑
摘要:# 信号量: # 跟 锁的概念一样 ,只不过可以设置钥匙的数量 import time import random from multiprocessing import Process from multiprocessing import Semaphore def fn(i,sem): sem 阅读全文
posted @ 2018-11-14 12:50 _Q 阅读(169) 评论(0) 推荐(0) 编辑
摘要:# 锁: # 每次程序只能让一个子进程进入(拿钥匙开锁,并再将门关上),其它进程没有钥匙就无法进去 # 当程序执行完毕时将钥匙放回,然后下一个子进程继续执行(下一个子进程拿钥匙进去) # 以此类推,也就是一次只能进入一个子进程 import json import time from multipr 阅读全文
posted @ 2018-11-14 12:48 _Q 阅读(333) 评论(0) 推荐(0) 编辑
摘要:# 守护进程: ! ! ! ( 一定是主进程的代码的结束 ) # 子进程会 随着主进程的 代码执行完毕 而结束 import time from multiprocessing import Process # p.terminate() 结束一个子进程 # p.name 当前进程的名字 # p.p 阅读全文
posted @ 2018-11-14 12:47 _Q 阅读(1632) 评论(0) 推荐(0) 编辑
摘要:# 自定义类 继承 Process 类# 必须实现一个 run 方法,run方法中是在子进程中执行的代码# 传参数: # 通过 super() 调用父类中的 __init__() 方法 import os from multiprocessing import Process class MyPro 阅读全文
posted @ 2018-11-14 12:45 _Q 阅读(313) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-14 12:44 _Q 阅读(664) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-14 12:43 _Q 阅读(598) 评论(0) 推荐(0) 编辑
摘要:# 进程的生命周期 # 开启了 子进程的主进程 # 主进程未结束:等待自己执行完毕,结束进程 # 子进程未结束:等待子进程执行完毕,结束进程 from multiprocessing import Process import os """ # 想让某些代码在同一个进程中执行 """ # os.ge 阅读全文
posted @ 2018-11-14 12:41 _Q 阅读(106) 评论(0) 推荐(0) 编辑
摘要:hmac 模块用于加密文件 类似于 hashlib 模块server import socket import os import hmac sk = socket.socket() sk.bind(('127.0.0.1',8080)) sk.listen() secret_key = b'q' 阅读全文
posted @ 2018-11-06 20:44 _Q 阅读(89) 评论(0) 推荐(0) 编辑
摘要:socketserver 模块可以在 TCP协议中 同时与多台客户端进行连接server import socketserver class MyServer(socketserver.BaseRequestHandler): def handle(self): while True: msg = 阅读全文
posted @ 2018-11-06 20:42 _Q 阅读(168) 评论(0) 推荐(0) 编辑
摘要:输入 dos 命令即可执行代码中的input server client 阅读全文
posted @ 2018-11-06 20:38 _Q 阅读(97) 评论(0) 推荐(0) 编辑
摘要:server client 阅读全文
posted @ 2018-11-06 20:35 _Q 阅读(89) 评论(0) 推荐(0) 编辑
摘要:server -- 接收端 client -- 发送端 阅读全文
posted @ 2018-11-06 20:31 _Q 阅读(184) 评论(0) 推荐(0) 编辑
摘要:server client 阅读全文
posted @ 2018-11-06 20:27 _Q 阅读(119) 评论(0) 推荐(0) 编辑
摘要:server client 阅读全文
posted @ 2018-11-06 20:26 _Q 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 20:23 _Q 阅读(168) 评论(0) 推荐(0) 编辑
摘要:# TCP 协议:'''服务端''' import socket # socket 模块 sk = socket.socket() # 创建一个 socket 对象 sk.bind(('127.0.0.1',8080)) # 给 server 端绑定一个 ip 和 端口 sk.listen() # 阅读全文
posted @ 2018-11-06 20:21 _Q 阅读(193) 评论(0) 推荐(0) 编辑
摘要:# server 服务端# client 客户端# broser 浏览器# arp 协议 :通过 ip 找 mac# ip :一台计算机再网路上的位置 # 公网 ip , 局域网 ip# 端口号:网络相关的程序才需要开一个端口,为的是能找到某台计算机上唯一的一个程序 # 再同一台计算机 同一时间 只 阅读全文
posted @ 2018-11-06 20:19 _Q 阅读(104) 评论(0) 推荐(0) 编辑
摘要:# login 登录# log 日志# logging# 什么叫日志?# 日志 用来记录用户行为 或者 代码的执行过程# print# logging# 我能够“一键”控制# 排错的时候需要打印很多细节来帮助我排错# 严重的错误记录下来# 有一些用户行为 有没有错都要记录下来 import logg 阅读全文
posted @ 2018-11-06 20:18 _Q 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 20:15 _Q 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 20:13 _Q 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 20:12 _Q 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 20:09 _Q 阅读(72) 评论(0) 推荐(0) 编辑
摘要:# 双下方法: # 1. __str__ # 2. __repr__ class A: def __str__(self): return "str_" def __repr__(self): return 'repr_' print(A) # 打印结果:<class '__main__.A'> - 阅读全文
posted @ 2018-11-06 20:07 _Q 阅读(63) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 20:05 _Q 阅读(80) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 20:04 _Q 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 20:03 _Q 阅读(79) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 20:01 _Q 阅读(320) 评论(0) 推荐(0) 编辑
摘要:69-python-类方法( classmethod ) 阅读全文
posted @ 2018-11-06 20:00 _Q 阅读(150) 评论(0) 推荐(0) 编辑
摘要:# property # 将方法伪装成一个属性 from math import pi class Circle: def __init__(self,r): self.r = r @property def perimter(self): return 2 * pi *self.r @proper 阅读全文
posted @ 2018-11-06 19:59 _Q 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2018-11-06 19:56 _Q 阅读(65) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示