随笔分类 - python
摘要:import json str=['abb',456,True,False] # json_str=json.dumps(str) # with open ('test.json','w') as f: # f.write(json_str) # with open ('test.json','w'
阅读全文
摘要:import pymysql conn=pymysql.connect( host='127.0.0.1', port=3306, user='root', password='999', database='day14', charset='utf8', autocommit=1 #自动提交,不设
阅读全文
摘要:from gevent import monkey;monkey.patch_all()import timefrom gevent import spawndef pp(): print('ppstar') time.sleep(2) print('ppover')def oo(): print(
阅读全文
摘要:from threading import Thread,Eventimport timeevent=Event()def wait(): print('wait==') time.sleep(2) print('over!') event.set()def go(i): print(f'{i},Z
阅读全文
摘要:from threading import Thread,Semaphore #类似锁的一个东西import timelock_num=Semaphore(2) #设置锁的数量def test(name): lock_num.acquire() print(f'{name}已加入') time.sl
阅读全文
摘要:from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutorimport timedef func(i): print('star', i) time.sleep(2) return f'over,{i}'def cb(r
阅读全文
摘要:import socketfrom threading import Threadserver = socket.socket(socket.AF_INET,socket.SOCK_STREAM)server.bind(('127.0.0.1',8080))server.listen(5)# def
阅读全文
摘要:from multiprocessing import Process,JoinableQueueimport randomimport timedef fang(jq,ll): for i in range(3): ran=random.randint(1,3) name=random.choic
阅读全文
摘要:from multiprocessing import Queue,Processdef fang(queue): queue.put('你愁啥')def qu(queue): print(queue.get())if __name__ == '__main__': q=Queue() p_fang
阅读全文
摘要:from multiprocessing import Queueq = Queue(3)q.put('aaa')q.put('bbb')q.put('ccc')print(q.full()) #判断当前队列是否已满print(q.empty()) #判断队列是否为空a = q.get()b = q
阅读全文
摘要:from multiprocessing import Process, Lockimport jsonimport timedef search(i): with open('data', 'r', encoding='utf8') as f: dic = json.load(f) num = d
阅读全文
摘要:1、去管网(https://www.python.org/downloads/source/),找Gzipped source tarball的链接 2、下载。wget 链接地址 3、解压。tar -xvf .tgz文件 4、切换到解压后的目录中(cd Python-3.8.7),执行./confi
阅读全文

浙公网安备 33010602011771号