当前位置: 首页 > news >正文

网站开发项目周期的wordpress 修改主题页面

网站开发项目周期的,wordpress 修改主题页面,公司建设网站申请信用卡,2023广东佛山最新感染病例1、程序工作原理 进程的限制#xff1a;每一个时刻只能有一个线程来工作。多进程的优点#xff1a;同时利用多个cpu#xff0c;能够同时进行多个操作。缺点#xff1a;对内存消耗比较高当进程数多于cpu数量的时候会导致不能被调用#xff0c;进程不是越多越好#xff0c;…1、程序工作原理     进程的限制每一个时刻只能有一个线程来工作。多进程的优点同时利用多个cpu能够同时进行多个操作。缺点对内存消耗比较高当进程数多于cpu数量的时候会导致不能被调用进程不是越多越好cpu与进程数量相等最好线程java和C# 对于一个进程里面的多个线程cpu都在同一个时刻能使用。py同一时刻只能调用一个。so对于型的应用py效率较java C#低。多线程优点共享进程的内存可以创造并发操作。缺点抢占资源多线程得时候系统在调用的时候需要记录请求上下文的信息请求上下文的切换 这个过程非常耗时。因此 线程不是越多越好具体案例具体分析。在计算机中执行任务的最小单元就是线程IO操作不利用CPUIO密集型操作适合多线程对于计算密集型适合多进程GIL全局解释器锁PY特有它会在每个进程上加个锁系统存在进程和线程的目的是为了提高效率 1.1、单进程单线程 1.2、自定义线程 主进程 主线程 子线程2、线程锁 threading.RLock和threading.Lock 多线程修改一个数据得时候可能会造成咱数据。建议使用rlock 3、线程时间threading.Event: 通知当有进程间的通讯的情况下这个才有应用场景。汽车类比线程Event.wait()红灯Event.set()绿灯Event.clear():使红灯变绿 even是线程间的通讯机制。Event.wait([timeout]):赌赛线程知道event对象内部标示位被设置为True或超时时间。Event.set()将标识位设为True。Event.clear():标识位设为False。Event.isSet():判断标识位是否为True。 4、queue模块生产者-消费者模型 #!/usr/bin/env python # -*- coding:utf-8 -*- import queue import threading # import queue# q queue.Queue(maxsize0) # 构造一个先进显出队列maxsize指定队列长度为0 时表示队列长度无限制。 # # q.join() # 等到队列为空的时候在执行别的操作 # q.qsize() # 返回队列的大小 不可靠 # q.empty() # 当队列为空的时候返回True 否则返回False 不可靠 # q.full() # 当队列满的时候返回True否则返回False 不可靠 # q.put(item, blockTrue, timeoutNone) # 将item放入Queue尾部item必须存在可以参数block默认为True,表示当队列满时会等待队列给出可用位置 # #                          为False时为非阻塞此时如果队列已满会引发queue.Full 异常。 可选参数timeout表示 会阻塞设置的时间过后 # #                          如果队列无法给出放入item的位置则引发 queue.Full 异常 # q.get(blockTrue, timeoutNone) # 移除并返回队列头部的一个值可选参数block默认为True表示获取值的时候如果队列为空则阻塞为False时不阻塞 # #                       若此时队列为空则引发 queue.Empty异常。 可选参数timeout表示会阻塞设置的时候过后如果队列为空则引发Empty异常。 # q.put_nowait(item) # 等效于 put(item,blockFalse) # q.get_nowait() # 等效于 get(item,blockFalse) message queue.Queue(10)def producer(i):print(put:,i)# while True:message.put(i)def consumer(i):# while True:msg message.get()print(msg)for i in range(12):t threading.Thread(targetproducer, args(i,))t.start()for i in range(10):t threading.Thread(targetconsumer, args(i,))t.start() qs message.qsize() print(当前消息队列的长度为:%d%(qs)) print(当前消息队列的长度为:,qs) queue示例代码 join()方法主线程等待最多等待时间可以hi设置egt.join(2) import threadingdef f0():passdef f1(a1,a2)time.sleep(10)f0()t threading.Thread(targetf1,args(111,222,))t.setDaemon(True) #默认false 主线程将等待执行完成后结束设置为true后主线程将不在等待t.start()t threading.Thread(targetf1,args(111,222,))t.start()t threading.Thread(targetf1,args(111,222,))t.start()t threading.Thread(targetf1,args(111,222,))t.start() threading demo 5、进程 multiprocess是py进程模块 进程之间默认是隔离得线程的资源默认是共享的 两个进程共享数据需要使用特殊得对象 array:其他语音 或manager.dict() 进程不是越多越好建议使用线程池来控制。 #!/usr/bin/env python # -*- coding:utf-8 -*- from multiprocessing import Pool import time def myFun(i):time.sleep(2)return i100def end_call(arg):print(end_call,arg)# print(p.map(myFun,range(10))) if __name__ __main__:p Pool(5)for i in range(10):p.apply_async(funcmyFun,args(i,),callbackend_call)print(end)p.close()p.join() porcesspooldemo #!/usr/bin/env python # -*- coding:utf-8 -*-from multiprocessing import Pool import timedef f1(a):time.sleep(1)print(a)return 1000 def f2(arg):print(arg)if __name__ __main__:pool Pool(5)for i in range(50):pool.apply_async(funcf1, args(i,),callbackf2)# pool.apply(funcf1, args(i,))print()pool.close()pool.join() processpooldemo2 6、线程池py没有提供我们需要自己编写 简单线程池示例 #!/usr/bin/env python # -*- coding:utf-8 -*- import queue import threading import timeclass ThreadPool(object):def __init__(self, max_num20):self.queue queue.Queue(max_num)for i in range(max_num):self.queue.put(threading.Thread)def get_thread(self):return self.queue.get()def add_thread(self):self.queue.put(threading.Thread)def func(pool,a1):time.sleep(2)print(a1)pool.add_thread()p ThreadPool(10)for i in range(100):#获得类thread p.get_thread()#对象 类#t thread(targetfunc,args(p,i,))t.start()pool ThreadPool(10)def func(arg, p):print argimport timetime.sleep(2)p.add_thread()for i in xrange(30):thread pool.get_thread()t thread(targetfunc, args(i, pool))t.start() # p ThreadPool() # ret p.get_thread() # # t ret(targetfunc,) # t.start() View Code 复杂的线城池示例 #!/usr/bin/env python # -*- coding:utf-8 -*-import queue import threading import contextlib import timeStopEvent object()class ThreadPool(object):def __init__(self, max_num, max_task_num None):if max_task_num:self.q queue.Queue(max_task_num)else:self.q queue.Queue()# 多大容量self.max_num max_numself.cancel Falseself.terminal False# 真实创建的线程列表self.generate_list []# 空闲线程数量self.free_list []def run(self, func, args, callbackNone):线程池执行一个任务:param func: 任务函数:param args: 任务函数所需参数:param callback: 任务执行失败或成功后执行的回调函数回调函数有两个参数1、任务函数执行状态2、任务函数返回值默认为None即不执行回调函数:return: 如果线程池已经终止则返回True否则Noneif self.cancel:returnif len(self.free_list) 0 and len(self.generate_list) self.max_num:self.generate_thread()w (func, args, callback,)self.q.put(w)def generate_thread(self):创建一个线程t threading.Thread(targetself.call)t.start()def call(self):循环去获取任务函数并执行任务函数# 获取当前进程current_thread threading.currentThread()self.generate_list.append(current_thread)# 取任务event self.q.get()while event ! StopEvent:# 是元组》是任务# 解开任务包# 执行任务 func, arguments, callback eventtry:result func(*arguments)success Trueexcept Exception as e:success Falseresult Noneif callback is not None:try:callback(success, result)except Exception as e:passwith self.worker_state(self.free_list, current_thread):if self.terminal:event StopEventelse:event self.q.get()else:# 不是元组不是任务# 标记我空闲了# 执行后线程死掉self.generate_list.remove(current_thread)def close(self):执行完所有的任务后所有线程停止self.cancel Truefull_size len(self.generate_list)while full_size:self.q.put(StopEvent)full_size - 1def terminate(self):无论是否还有任务终止线程self.terminal Truewhile self.generate_list:self.q.put(StopEvent)self.q.empty()contextlib.contextmanagerdef worker_state(self, state_list, worker_thread):用于记录线程中正在等待的线程数state_list.append(worker_thread)try:yieldfinally:state_list.remove(worker_thread)# How to use pool ThreadPool(5)def callback(status, result):# status, execute action status# result, execute action return valuepassdef action(i):print(i)for i in range(30):#将任务放在队列#着手开始处理任务#创建线程有空闲线程则不创建不高于线程池的限制根据任务个数判断 》线程去队列中去任务ret pool.run(action, (i,), callback)time.sleep(5) print(len(pool.generate_list), len(pool.free_list)) print(len(pool.generate_list), len(pool.free_list)) # pool.close() # pool.terminate() View Code  7、上下文管理 #!/usr/bin/env python # -*- coding:utf-8 -*- import queue import contextlibq queue.Queue() li []# li.append(1) # q.get() # li.remove(1)contextlib.contextmanager def worker_stater(xxx,val):xxx.append(val)try:yield 123finally:xxx.remove(val)q.put(john) with worker_stater(li,1) as f:print(before,li)print(f)q.get()passpassprint(after,li) contextlib.contextmanager def myopen(file_path,mode):f open(file_path,mode,encodingutf-8)try:yield ffinally:f.close()with myopen(index.html,r) as file_obj:print(file_obj.readline()) demo 8、协程 协程主要应用在IO密集型场景由程序来控制也叫微线程高性能通常与协程挂钩 #!/usr/bin/env python # -*- coding:utf-8 -*- import geventdef foo():print(Running in foo)gevent.sleep(0) #切换协程print(Explicit context switch to foo agein) def bar():print(Running in bar)gevent.sleep(0) #切换协程print(Explicit context switch back to bar agein)gevent.joinall([gevent.spawn(foo),gevent.spawn(bar), ]) demo1 #!/usr/bin/env python # -*- coding:utf-8 -*- from gevent import monkey;monkey.patch_all() import gevent import requestsdef f(url):print(GET:%s % url)resp requests.get(url)data resp.textprint(url,len(data))gevent.joinall([gevent.spawn(f,http://www.python.org/),gevent.spawn(f,https://www.yahoo.com/),gevent.spawn(f,https://github.com/), ]) demo2 #!/usr/bin/env python # -*- coding:utf-8 -*-from greenlet import greenletdef test1():print(12)gr2.switch()print(34)gr2.switch()def test2():print(56)gr1.switch()print(78)gr1.switch()gr1 greenlet(test1) gr2 greenlet(test2)gr1.switch() demo3   end转载于:https://www.cnblogs.com/workherd/p/8809764.html
http://www.yutouwan.com/news/430454/

相关文章:

  • 论坛与网站做优化哪个更好网站开发人员年薪
  • 怎样看网站做的好不好瑞安塘下做网站的公司
  • 四川省住房建设厅网站打不开网站建设中的背景图片模板
  • 360老是提示危险网站邯郸网站建设效果好
  • 织梦wap手机网站模板自助建站网站模板
  • 金阳建设集团网站陕西省城乡住房建设厅网站
  • 网站开发工具和平台房山广州网站建设
  • 网站建设与管理资料下载青岛君哲网站建设公司怎么样
  • 汕头市建设局网站松江 网站建设公司
  • 云网站注册seo优化工具
  • 美克美家网站建设公司网页制作需要多少钱
  • 网站建设发展史赛尔网络公司好不好
  • 与做机器人有关的网站网站的折线图怎么做
  • 购物网站 wordpress 英文模板汕头制作公司网站
  • 网站打不开h5 WordPress
  • 专门做钱币的网站网站建设顾问站建
  • 北京云建站模板wordpress移动端顶部导航栏
  • 西安整站优化做餐厅网站的需求分析报告
  • 邵阳市 网站建设怎么用asp.net做网站
  • 家具全屋定制龙华优化公司
  • 毕业设计网站wordpress房产主题汉化版
  • 建站高端网站网站建设修改建议书
  • 国家中小企业公共服务平台无线网络优化
  • 如何建设网站地图河源seo排名
  • 比较大的建站公司西安SEO网站排名
  • 中英文网站用同域名...温岭做网站
  • 网站开发工作进展情况动漫做的游戏 迅雷下载网站
  • 资讯类网站模板asp食品建设网站的目的
  • 建网站一般多少钱深圳也放开了
  • 网站开发语言有什么ps做网站图