随笔分类 - python
摘要:code macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % cat test.py import logging logging.basicConfig(level=logging.INFO, filename
阅读全文
摘要:code from queue import Queue from threading import Thread # 用来表示终止的特殊对象 _sentinel = object() # A thread that produces data def producer(out_q): for i
阅读全文
摘要:code from queue import Queue from threading import Thread class Producer(Thread): def __init__(self, q): super().__init__() self.count = 5 self.q = q
阅读全文
摘要:code import multiprocessing from multiprocessing import Pool,Queue import time import threading import gevent from gevent import monkey monkey.patch_a
阅读全文
摘要:python中Queue是消息队列,提供线程间通信机制,python3中重名为为queue Queue模块中的类:Queue(maxsize=0):创建一个FIFO队列,若给定最大值,队列没有空间时阻塞,否则是无限队列LifoQueue(maxsize=0):创建一个栈,maxsize含义同上Pri
阅读全文
摘要:code import threading import time from queue import Queue def test(data,que,index): for i in data: if(i==8900): que.put(i) print(index," ",i) pass if
阅读全文
摘要:code import multiprocessing from multiprocessing import Pool import time import threading g_num = 0 def test1(): for i in range(10): time.sleep(1) pri
阅读全文
摘要:code import time import threading class MyCounter(threading.Thread): """自定义线程类型,继承threading.Thread类""" # 类属性 num = 1 def run(self): """重写run方法,在线程star
阅读全文
摘要:code import gevent,time from gevent import monkey monkey.patch_all() #gevent三行放在其他所有import语句之前可以避免出现警告或者报错信息,导致程序不能正常运行 def test1(): for i in range(10
阅读全文
摘要:code """ 守护线程:一个子线程,会随着主线程的退出直接退出 不论子线程中是否执行完成 不离不弃,死生相随 """ import threading import time def test(): while True: print(f"{threading.current_thread().
阅读全文
摘要:code macname@MacdeMBP Desktop % macname@MacdeMBP Desktop % cat test.py import time from multiprocessing import Process def func(name, sec): print(name
阅读全文
摘要:code macname@MacdeMBP Desktop % macname@MacdeMBP Desktop % cat test.py import time from multiprocessing import Process def func(name): print(f"我是{name
阅读全文
摘要:code macname@localhost Desktop % cat exce.py import sys def tmp_func(): print(sys._getframe().f_code.co_name) tmp_func() macname@localhost Desktop % p
阅读全文
摘要:code import time import datetime t1=time.time() time.sleep(0.02) t2=time.time() print("相差",(datetime.datetime.fromtimestamp(t2)-datetime.datetime.from
阅读全文
摘要:code import json new_dict={"func_name":"https://www.cnblogs.com/bigberg/p/6430095.html"} with open("record.json","w") as f: json.dump(new_dict,f) with
阅读全文
摘要:code import hashlib from cv2 import VideoCapture from moviepy.editor import * import os dir_paths = os.path.join(os.path.dirname(os.path.abspath(__fil
阅读全文
摘要:code1 import os import shutil pwd=os.getcwd() fpath=os.path.join(pwd,"dian") target=os.path.join(pwd,"电子书") c=0 for i in os.listdir(fpath): d=os.path.
阅读全文
摘要:code # !/usr/bin/python # -*- coding:utf-8 -*- # time: 2019/07/21--20:12 __author__ = 'Henry' ''' 项目: B站动漫番剧(bangumi)下载 版本2: 无加密API版,但是需要加入登录后cookie中的
阅读全文
摘要:code with open("test") as f: for line in f.readlines(): if(line): print(line,"<br>")
阅读全文
摘要:code import os import shutil pwd=os.getcwd() for i in os.listdir(pwd): d=os.path.join(pwd,i) if(os.path.isdir(d)): for j in os.listdir(d): f=os.path.j
阅读全文