当前位置: 首页 > 编程日记 > 正文

python多进程详解

目录

  • python多进程
    • 序.multiprocessing
    • 一、Process
      • process介绍
      • 例1.1:创建函数并将其作为单个进程
      • 例1.2:创建函数并将其作为多个进程
      • 例1.3:将进程定义为类
      • 例1.4:daemon程序对比结果
    • 二、Lock
    • 三、Semaphore
    • 四、Event
    • 五、Queue
    • 六、Pipe
    • 七、Pool
      • 例7.1:使用进程池(非阻塞)
      • 例7.2:使用进程池(阻塞)
      • 例7.3:使用进程池,并关注结果
      • 例7.4:使用多个进程池

python多进程

序.multiprocessing

python中的多线程其实并不是真正的多线程,如果想要充分地使用多核CPU的资源,在python中大部分情况需要使用多进程。Python提供了非常好用的多进程包multiprocessing,只需要定义一个函数,Python会完成其他所有事情。借助这个包,可以轻松完成从单进程到并发执行的转换。multiprocessing支持子进程、通信和共享数据、执行不同形式的同步,提供了Process、Queue、Pipe、Lock等组件。

一、Process

process介绍

  • 创建进程的类:Process([group [, target [, name [, args [, kwargs]]]]]),target表示调用对象,args表示调用对象的位置参数元组。kwargs表示调用对象的字典。name为别名。group实质上不使用。

  • 方法:is_alive()、join([timeout])、run()、start()、terminate()。其中,Process以start()启动某个进程。

  • 属性:authkey、daemon(要通过start()设置)、exitcode(进程在运行时为None、如果为–N,表示被信号N结束)、name、pid。其中daemon是父进程终止后自动终止,且自己不能产生新进程,必须在start()之前设置。

例1.1:创建函数并将其作为单个进程

import multiprocessing
import timedef worker(interval):n = 5while n > 0:print("The time is {0}".format(time.ctime()))time.sleep(interval)n -= 1if __name__ == "__main__":p = multiprocessing.Process(target = worker, args = (3,))p.start()print("p.pid:", p.pid)print("p.name:", p.name)print("p.is_alive:", p.is_alive())------------------------------------------------>>> p.pid: 1004
>>> p.name: Process-1
>>> p.is_alive: True
>>> The time is Mon Jul 29 21:31:11 2019
>>> The time is Mon Jul 29 21:31:14 2019
>>> The time is Mon Jul 29 21:31:17 2019
>>> The time is Mon Jul 29 21:31:20 2019
>>> The time is Mon Jul 29 21:31:23 2019

例1.2:创建函数并将其作为多个进程

import multiprocessing
import timedef worker_1(interval):print("worker_1")time.sleep(interval)print("end worker_1")def worker_2(interval):print("worker_2")time.sleep(interval)print("end worker_2")def worker_3(interval):print("worker_3")time.sleep(interval)print("end worker_3")if __name__ == "__main__":p1 = multiprocessing.Process(target = worker_1, args = (2,))p2 = multiprocessing.Process(target = worker_2, args = (3,))p3 = multiprocessing.Process(target = worker_3, args = (4,))p1.start()p2.start()p3.start()print("The number of CPU is:" + str(multiprocessing.cpu_count()))for p in multiprocessing.active_children():print("child   p.name:" + p.name + "\tp.id" + str(p.pid))print("END")------------------------------------------------>>> The number of CPU is:8
>>> child   p.name:Process-3    p.id18208
>>> child   p.name:Process-2    p.id1404
>>> child   p.name:Process-1    p.id11684
>>> END
>>> worker_1
>>> worker_2
>>> worker_3
>>> end worker_1
>>> end worker_2
>>> end worker_3

例1.3:将进程定义为类

import multiprocessing
import timeclass ClockProcess(multiprocessing.Process):def __init__(self, interval):multiprocessing.Process.__init__(self)self.interval = intervaldef run(self):n = 5while n > 0:print("the time is {0}".format(time.ctime()))time.sleep(self.interval)n -= 1if __name__ == '__main__':p = ClockProcess(3)p.start() ------------------------------------------------>>> the time is Mon Jul 29 21:43:07 2019
>>> the time is Mon Jul 29 21:43:10 2019
>>> the time is Mon Jul 29 21:43:13 2019
>>> the time is Mon Jul 29 21:43:16 2019
>>> the time is Mon Jul 29 21:43:19 2019

:进程p调用start()时,自动调用run()

例1.4:daemon程序对比结果

1.4-1 不加daemon属性

import multiprocessing
import timedef worker(interval):print("work start:{0}".format(time.ctime()));time.sleep(interval)print("work end:{0}".format(time.ctime()));if __name__ == "__main__":p = multiprocessing.Process(target = worker, args = (3,))p.start()print("end!")------------------------------------------------>>> end!
>>> work start:Tue Jul 29 21:29:10 2019
>>> work end:Tue Jul 29 21:29:13 2019

1.4-2 加上daemon属性

import multiprocessing
import timedef worker(interval):print("work start:{0}".format(time.ctime()));time.sleep(interval)print("work end:{0}".format(time.ctime()));if __name__ == "__main__":p = multiprocessing.Process(target = worker, args = (3,))p.daemon = Truep.start()print("end!")------------------------------------------------>>> end!

:因子进程设置了daemon属性,主进程结束,它们就随着结束了。

1.4-3 设置daemon执行完结束的方法

import multiprocessing
import timedef worker(interval):print("work start:{0}".format(time.ctime()));time.sleep(interval)print("work end:{0}".format(time.ctime()));if __name__ == "__main__":p = multiprocessing.Process(target = worker, args = (3,))p.daemon = Truep.start()p.join()print("end!")------------------------------------------------>>> work start:Tue Jul 29 22:16:32 2019
>>> work end:Tue Jul 29 22:16:35 2019
>>> end!

二、Lock

当多个进程需要访问共享资源的时候,Lock可以用来避免访问的冲突。

import multiprocessing
import sysdef worker_with(lock, f):with lock:fs = open(f, 'a+')n = 10while n > 1:fs.write("Lockd acquired via with\n")n -= 1fs.close()def worker_no_with(lock, f):lock.acquire()try:fs = open(f, 'a+')n = 10while n > 1:fs.write("Lock acquired directly\n")n -= 1fs.close()finally:lock.release()if __name__ == "__main__":lock = multiprocessing.Lock()f = "file.txt"w = multiprocessing.Process(target = worker_with, args=(lock, f))nw = multiprocessing.Process(target = worker_no_with, args=(lock, f))w.start()nw.start()print("end")------------------------------------------------>>> Lockd acquired via with
>>> Lockd acquired via with
>>> Lockd acquired via with
>>> Lockd acquired via with
>>> Lockd acquired via with
>>> Lockd acquired via with
>>> Lockd acquired via with
>>> Lockd acquired via with
>>> Lockd acquired via with
>>> Lock acquired directly
>>> Lock acquired directly
>>> Lock acquired directly
>>> Lock acquired directly
>>> Lock acquired directly
>>> Lock acquired directly
>>> Lock acquired directly
>>> Lock acquired directly
>>> Lock acquired directly

三、Semaphore

Semaphore用来控制对共享资源的访问数量,例如池的最大连接数。

import multiprocessing
import timedef worker(s, i):s.acquire()print(multiprocessing.current_process().name + "acquire");time.sleep(i)print(multiprocessing.current_process().name + "release\n");s.release()if __name__ == "__main__":s = multiprocessing.Semaphore(2)for i in range(5):p = multiprocessing.Process(target = worker, args=(s, i*2))p.start()------------------------------------------------>>> Process-1acquire
>>> Process-1release
>>>  
>>> Process-2acquire
>>> Process-3acquire
>>> Process-2release
>>>  
>>> Process-5acquire
>>> Process-3release
>>>  
>>> Process-4acquire
>>> Process-5release
>>>  
>>> Process-4release

四、Event

Event用来实现进程间同步通信。

import multiprocessing
import timedef wait_for_event(e):print("wait_for_event: starting")e.wait()print("wairt_for_event: e.is_set()->" + str(e.is_set()))def wait_for_event_timeout(e, t):print("wait_for_event_timeout:starting")e.wait(t)print("wait_for_event_timeout:e.is_set->" + str(e.is_set()))if __name__ == "__main__":e = multiprocessing.Event()w1 = multiprocessing.Process(name = "block",target = wait_for_event,args = (e,))w2 = multiprocessing.Process(name = "non-block",target = wait_for_event_timeout,args = (e, 2))w1.start()w2.start()time.sleep(3)e.set()print("main: event is set")------------------------------------------------>>> wait_for_event: starting
>>> wait_for_event_timeout:starting
>>> wait_for_event_timeout:e.is_set->False
>>> main: event is set
>>> wairt_for_event: e.is_set()->True

五、Queue

Queue是多进程安全的队列,可以使用Queue实现多进程之间的数据传递。put方法用以插入数据到队列中,put方法还有两个可选参数:blocked和timeout。如果blocked为True(默认值),并且timeout为正值,该方法会阻塞timeout指定的时间,直到该队列有剩余的空间。如果超时,会抛出Queue.Full异常。如果blocked为False,但该Queue已满,会立即抛出Queue.Full异常。

get方法可以从队列读取并且删除一个元素。同样,get方法有两个可选参数:blocked和timeout。如果blocked为True(默认值),并且timeout为正值,那么在等待时间内没有取到任何元素,会抛出Queue.Empty异常。如果blocked为False,有两种情况存在,如果Queue有一个值可用,则立即返回该值,否则,如果队列为空,则立即抛出Queue.Empty异常。Queue的一段示例代码:

import multiprocessingdef writer_proc(q):      try:         q.put(1, block = False) except:         pass   def reader_proc(q):      try:         print(q.get(block = False))except:         passif __name__ == "__main__":q = multiprocessing.Queue()writer = multiprocessing.Process(target=writer_proc, args=(q,))  writer.start()   reader = multiprocessing.Process(target=reader_proc, args=(q,))  reader.start()  reader.join()  writer.join()------------------------------------------------>>> 1

六、Pipe

Pipe方法返回(conn1, conn2)代表一个管道的两个端。Pipe方法有duplex参数,如果duplex参数为True(默认值),那么这个管道是全双工模式,也就是说conn1和conn2均可收发。duplex为False,conn1只负责接受消息,conn2只负责发送消息。

send和recv方法分别是发送和接受消息的方法。例如,在全双工模式下,可以调用conn1.send发送消息,conn1.recv接收消息。如果没有消息可接收,recv方法会一直阻塞。如果管道已经被关闭,那么recv方法会抛出EOFError。

import multiprocessing
import timedef proc1(pipe):while True:for i in range(10000):print("send: %s" %(i))pipe.send(i)time.sleep(1)def proc2(pipe):while True:print("proc2 rev:", pipe.recv())time.sleep(1)def proc3(pipe):while True:print("PROC3 rev:", pipe.recv())time.sleep(1)if __name__ == "__main__":pipe = multiprocessing.Pipe()p1 = multiprocessing.Process(target=proc1, args=(pipe[0],))p2 = multiprocessing.Process(target=proc2, args=(pipe[1],))# p3 = multiprocessing.Process(target=proc3, args=(pipe[1],))p1.start()p2.start()# p3.start()p1.join()p2.join()# p3.join()------------------------------------------------>>> send: 0
>>> roc2 rev: 0
>>> send: 1
>>> proc2 rev: 1
>>> send: 2
>>> proc2 rev: 2
>>> send: 3
>>> proc2 rev: 3
>>> send: 4
>>> proc2 rev: 4
>>> send: 5
>>> proc2 rev: 5
>>> send: 6
>>> proc2 rev: 6
>>> send: 7
>>> proc2 rev: 7
>>> send: 8
>>> proc2 rev: 8......

七、Pool

在利用Python进行系统管理的时候,特别是同时操作多个文件目录,或者远程控制多台主机,并行操作可以节约大量的时间。当被操作对象数目不大时,可以直接利用multiprocessing中的Process动态成生多个进程,十几个还好,但如果是上百个,上千个目标,手动的去限制进程数量却又太过繁琐,此时可以发挥进程池的功效。
Pool可以提供指定数量的进程,供用户调用,当有新的请求提交到pool中时,如果池还没有满,那么就会创建一个新的进程用来执行该请求;但如果池中的进程数已经达到规定最大值,那么该请求就会等待,直到池中有进程结束,才会创建新的进程来它。

例7.1:使用进程池(非阻塞)

import multiprocessing
import timedef func(msg):print("msg:", msg)time.sleep(3)print("end")if __name__ == "__main__":pool = multiprocessing.Pool(processes = 3)for i in range(4):msg = "hello %d" %(i)pool.apply_async(func, (msg, ))   #维持执行的进程总数为processes,当一个进程执行完毕后会添加新的进程进去print("Mark~ Mark~ Mark~~~~~~~~~~~~~~~~~~~~~~")pool.close()pool.join()   #调用join之前,先调用close函数,否则会出错。执行完close后不会有新的进程加入到pool,join函数等待所有子进程结束print("Sub-process(es) done.")------------------------------------------------>>> Mark~ Mark~ Mark~~~~~~~~~~~~~~~~~~~~~~
>>> msg: hello 0
>>> msg: hello 1
>>> msg: hello 2
>>> end
>>> msg: hello 3
>>> end
>>> end
>>> end
>>> Sub-process(es) done.

函数解释:

  • apply_async(func[, args[, kwds[, callback]]]) 它是非阻塞,apply(func[, args[, kwds]])是阻塞的(理解区别,看例1例2结果区别)
  • close() 关闭pool,使其不在接受新的任务。
  • terminate() 结束工作进程,不在处理未完成的任务。
  • join() 主进程阻塞,等待子进程的退出, join方法要在close或terminate之后使用。

执行说明:创建一个进程池pool,并设定进程的数量为3,xrange(4)会相继产生四个对象[0, 1, 2, 4],四个对象被提交到pool中,因pool指定进程数为3,所以0、1、2会直接送到进程中执行,当其中一个执行完事后才空出一个进程处理对象3,所以会出现输出“msg: hello 3”出现在"end"后。因为为非阻塞,主函数会自己执行自个的,不搭理进程的执行,所以运行完for循环后直接输出“mMsg: hark~ Mark~ Mark~~~~~~~~~~~~~~~~~~~~~~”,主程序在pool.join()处等待各个进程的结束。

例7.2:使用进程池(阻塞)

import multiprocessing
import timedef func(msg):print("msg:", msg)time.sleep(3)print("end")if __name__ == "__main__":pool = multiprocessing.Pool(processes = 3)for i in range(4):msg = "hello %d" %(i)pool.apply(func, (msg, ))   #维持执行的进程总数为processes,当一个进程执行完毕后会添加新的进程进去print("Mark~ Mark~ Mark~~~~~~~~~~~~~~~~~~~~~~")pool.close()pool.join()   #调用join之前,先调用close函数,否则会出错。执行完close后不会有新的进程加入到pool,join函数等待所有子进程结束print("Sub-process(es) done.")------------------------------------------------>>> msg: hello 0
>>> end
>>> msg: hello 1
>>> end
>>> msg: hello 2
>>> end
>>> msg: hello 3
>>> end
>>> Mark~ Mark~ Mark~~~~~~~~~~~~~~~~~~~~~~
>>> Sub-process(es) done.

例7.3:使用进程池,并关注结果

import multiprocessing
import timedef func(msg):print("msg:", msg)time.sleep(3)print("end")return "done" + msgif __name__ == "__main__":pool = multiprocessing.Pool(processes=4)result = []for i in range(3):msg = "hello %d" %(i)result.append(pool.apply_async(func, (msg, )))pool.close()pool.join()for res in result:print(":::", res.get())print("Sub-process(es) done.")------------------------------------------------>>> msg: hello 0
>>> msg: hello 1
>>> msg: hello 2
>>> end
>>> end
>>> end
>>> ::: donehello 0
>>> ::: donehello 1
>>> ::: donehello 2
>>> Sub-process(es) done.

例7.4:使用多个进程池

import multiprocessing
import os, time, randomdef Lee():print("\nRun task Lee-%s" % (os.getpid()))  # os.getpid()获取当前的进程的IDstart = time.time()time.sleep(random.random() * 10)  # random.random()随机生成0-1之间的小数end = time.time()print('Task Lee, runs %0.2f seconds.' % (end - start))def Marlon():print("\nRun task Marlon-%s" % (os.getpid()))start = time.time()time.sleep(random.random() * 40)end = time.time()print('Task Marlon runs %0.2f seconds.' % (end - start))def Allen():print("\nRun task Allen-%s" % (os.getpid()))start = time.time()time.sleep(random.random() * 30)end = time.time()print('Task Allen runs %0.2f seconds.' % (end - start))def Frank():print("\nRun task Frank-%s" % (os.getpid()))start = time.time()time.sleep(random.random() * 20)end = time.time()print('Task Frank runs %0.2f seconds.' % (end - start))if __name__ == '__main__':function_list = [Lee, Marlon, Allen, Frank]print("parent process %s" % (os.getpid()))pool = multiprocessing.Pool(4)for func in function_list:pool.apply_async(func)  # Pool执行函数,apply执行函数,当有一个进程执行完毕后,会添加一个新的进程到pool中print('Waiting for all subprocesses done...')pool.close()pool.join()  # 调用join之前,一定要先调用close() 函数,否则会出错, close()执行后不会有新的进程加入到pool,join函数等待素有子进程结束print('All subprocesses done.')------------------------------------------------>>> parent process 9828
>>> Waiting for all subprocesses done...
>>> 
>>> Run task Lee-12948
>>> 
>>> Run task Marlon-8948
>>> 
>>> Run task Allen-18124
>>> 
>>> Run task Frank-17404
>>> Task Frank runs 3.42 seconds.
>>> Task Lee, runs 6.69 seconds.
>>> Task Allen runs 8.38 seconds.
>>> Task Marlon runs 13.37 seconds.
>>> All subprocesses done.

转载于:https://www.cnblogs.com/luyuze95/p/11266951.html

相关文章:

【工具软件】webstorm的实用快捷操作(持续积累)

博主目前正在做前端的开发,使用到了一个十分实用的软件叫webstom,昨天做了一个破解教程的博客,但是审核没有通过,有兴趣的朋友可以私信我。webstom的实用之处就在于它数不胜数的快捷操作大大简化了写代码的繁琐步骤。但是那么多的…

无线Trace脚本(旧格式)-平均延时

BEGIN {#程序初始化,设定一变量以记录目前处理的封包的最大ID号码。在awk环境下变量的使用不需要声明,直接赋值。highest_uid 0;total_packet0;total_delay_time0; } #下面大括号里面的内容会针对要进行处理的记录(也就是我们的trace文件&am…

友元函数、类的非静态成员函数、静态成员函数的区别

类中申明的函数相对于类来说有三层意思:1.有this指针2.函数在类的作用区域中3.可以访问类中私有部分 4.可以被继承非静态成员函数具有1234静态成员函数具有234友元函数具有3静态成员函数与友元函数的区别只是作用区域的不同 友元函数具有全局性 不慎使用可能会造成函…

【转载】“error LNK1169: 找到一个或多个多重定义的符号”的解决方法

c的小细节的地方 原文地址:https://blog.csdn.net/xiaosu123/article/details/5665729 问题描述如下: 有 三个源文件,A.h、B.cpp、C.cpp。 A.h是头文件,其中声明了三个变量a1、a2、 a3。 B.cpp是A.h中所声明的类的实现源代码&…

【jQuery】jQuery知识点梳理(持续更新)

jQuery是什么: 由图标可知: j:JavaScript query:查询 所以可以分析得jQuery是一个JavaScript库,而且主要用来查询。 注意,下面的一行小字,write less do more 我们不仅可以看出jQuery以高效…

Python - 在CentOS7.5系统中安装Python3

注意:以下内容均使用root用户执行操作。 1-确认信息 # uname -a Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux # # cat /etc/system-release CentOS Linux release 7.5.1804 (Core) # …

JQuery 基础:8.节点操作

1.replaceWith替换节点 $("br").replaceWith("<hr/>"); 2.wrap()包裹节点,将元素逐个用指定标签包裹 $("b").wrap("<font colorred></font>")转载于:https://www.cnblogs.com/xyangs/archive/2012/05/22/2513821.ht…

《CLR Via C# 第3版》笔记之(十四) - 泛型高级

为了更好的利用泛型&#xff0c;现将泛型的一些高级特性总结一下。 主要内容&#xff1a; 泛型的协变和逆变泛型的参数的约束1. 泛型的协变和逆变 对于泛型参数(一般用T表示)&#xff0c;指定了类型之后。就只能识别此类型&#xff0c;面向对象中的继承并不适用泛型参数&#x…

剑指offer-反转链表

输入一个链表&#xff0c;反转链表后&#xff0c;输出链表的所有元素。 #-*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val x # self.next None class Solution:# 返回ListNodedef ReverseList(self, pHead):# write code h…

[NOIP模拟测试9]题(Problem) 题解 (组合数全家桶+dp)

达哥送分给我我都不要&#xff0c;感觉自己挺牛批。 $type0:$ 跟visit那题类似&#xff0c;枚举横向移动的步数直接推公式&#xff1a; $ans\sum C_n^i \times C_i^{\frac{i}{2}} \times C_{n-i}^{\frac{n-i}{2}},i\% 20$ $type1:$ 因为不能触碰负半轴&#xff0c;所以可以把右…

如何获取元素最终使用的css值

这个问题是在组件css加载方案中碰到的 场景&#xff1a; 元素的样式我们可以写在style里面&#xff0c;也可以写到外链css里面&#xff0c;如果没有设置&#xff0c;也会读取浏览器默认的css的&#xff0c;现在我们要计算getComputedstyle某个元素的最终所使用的css样式 区别&a…

【工具软件】webstorm如何使用快捷键生成固定代码

我们写前端页面时会有很多的机械重复代码&#xff0c;每写一个文件都要重新写一遍&#xff0c;枯燥且浪费时间&#xff0c;有没有一个方法可以快速生成这些代码呢&#xff1f;有&#xff01;webstorm替我们考虑到了这个问题&#xff0c;提供了解决方案&#xff0c;接下来让我们…

Citrix Receiver For Linux 预览版

Citrix各平台的客户端插件都在不断的完善和进行版本升级&#xff0c;但是For linux版本的ICA Client基本是一成不变&#xff0c;很长时间都不会有什么动静&#xff0c;但是Citrix产品都是搭配ThinClient来使用&#xff0c;而好多ThinClient都会使用Linux系统&#xff0c;而在Li…

5.20 单词小记

1.cart n. 二轮运货马车 vt. 用车装载 vi. 驾运货马车&#xff1b;用运货车运送 网络释义:购物车,小车,球车,分类与回归树 例:This would allow the server application to identify the cart from which it should add and removeitems. 这将使服务器应用程序能够确定它所应该…

windows性能计数器搜集方法

windows性能计数器搜集方法 PerfMon-Windows性能监视器是个好东西&#xff0c;可以辅助我们分析发生问题时间段服务器资源占用情况&#xff0c;但是部署性能计数器确实一个相当麻烦的事情&#xff0c;往往这种枯燥的事别人还做不了&#xff0c;只能由我们这些希望获取到PerfMon…

【HDU】3308 LCIS

1 #include<cstdio>2 #define MAXN 1000103 struct node4 {5 int left,right,val;6 };7 int a[MAXN];8 node tree[MAXN<<2];9 inline int MAX(int x,int y) 10 { 11 return x>y?x:y; 12 } 13 inline int MIN(int x,int y) 14 { 15 return x>y?…

【基础知识】如何在浏览器中查找元素属性节点

首先&#xff0c;什么是属性节点&#xff1f;属性节点是在编写html代码时&#xff0c;在html标签中添加的属性。 本文重点&#xff1a;如果您用的ie&#xff0c;我恳请您不要在用了&#xff0c;你们的每次使用都是打在前端工程师身上的一发子弹 代码实例&#xff1a; <!DOC…

C#系列五《多样化的程序分支》

上一篇介绍了C#程序设计分支的基本概念与基本操作&#xff0c;这篇的主题是高级的程序分支&#xff0c;例如&#xff1a;分支的嵌套与分支是使用的场景&#xff01;与三元运算符(&#xff1f;:),废话少说还是开始吧&#xff01; 1.三元运算符【&#xff1f;:】 三元运算符分为三…

Vue报错:Uncaught RangeError: Maximum call stack size exceeded

vue项目放在服务器上&#xff0c;报错如下&#xff1a; 堆栈溢出&#xff1a; 1、原因&#xff1a;有小类到大类的递归查询导致溢出 2、解决方法思想&#xff1a; A、在做递归查询时候由大类到小类去查询 B、匹配结果后及时return 退出&#xff0c;防止过多查询 转载于:https:/…

【Echarts】当页面宽度改变时如何使图表宽度自适应

问题&#xff1a; 当对echats不作任何处理时&#xff0c;图表宽度不会自适应&#xff0c;如图所示&#xff08;变绿的区域为echarts选中的div&#xff09;。 加载完后&#xff1a; 收缩浏览器页面之后&#xff1a; 解决方法&#xff1a; 编写js函数&#xff0c;当页面大小变…

【C#】登陆次数限制

我们在网上登陆的时候有些网站在用户多次输错密码之后会自动把账户冻结&#xff0c;不能在进行登陆&#xff0c;笔者这次做的winform程序就是要实现这种功能。 功能一&#xff1a;根据数据库字段判断用户名和密码是否匹配&#xff1b; 功能二&#xff1a;如果输入错误自动记录连…

linux 使用sendmail发送邮件

1111111111 转载于:https://www.cnblogs.com/We612/p/11274139.html

[转]MySQL innoDB数据插入性能优化

转载自: http://hiyijian.blog.163.com/blog/static/173086472201121621326471/ 起因&#xff1a;有一个innoDB引擎的表Table&#xff0c;在一个大概3000次的foreach循环中执行 INSERT INTO Table(columnA, columnB) VALUES (valueA, valueB)结果居然超出了60S的php执行限制&am…

vue+ivew-admin开发项目,内存占用过大解决办法

项目用的ivewadmin ivewUI&#xff0c;直接从github上拉下来用的&#xff0c;配置也没改&#xff0c;我们页面比较多&#xff0c;大该30个页面的样子&#xff0c;一启用&#xff0c;我们的电脑就卡了&#xff0c;然后&#xff0c;看一下&#xff0c;内存占用 1.5G了&#xff0c…

腾讯微视:向前一步是悲壮,向后一步是绝望zz

“换做以往的任何一场战争&#xff0c;微博之战、搜索之战和电商之战——大量投入但始终不见效果&#xff0c;打到现在腾讯肯定已经交牌了。微视的不同之处在于&#xff0c;它有些悲壮&#xff0c;因为这是腾讯最不想交出的一张牌。” 文 | 《财经》记者高洪浩 编辑|宋玮 如果有…

[C]线程中的数据

线程的私有存储空间包括&#xff1a; 栈&#xff08;一般情况下是私有的&#xff09;线程局部存储&#xff08;部分操作系统提供&#xff09;寄存器&#xff08;包括PC寄存器&#xff09; 从C程序员的角度来看&#xff1a; 线程私有&#xff1a; 局部变量函数的参数线程局部存储…

【css】如何使页面压缩时文本内容不换行

问题描述&#xff1a; 当页面变小时&#xff0c;有些情况下会出现下图所示的情况&#xff0c;即文本自动换行 页面变小前&#xff1a; 变小后: 解决方法&#xff1a; 使用CSS添加一个控制语句 .fence_control{white-space: nowrap; } 并在文本所在的标签属性中添加该控制 …

程序员面试题精选100题(61)-数对之差的最大值

题目&#xff1a;在数组中&#xff0c;数字减去它右边的数字得到一个数对之差。求所有数对之差的最大值。例如在数组{2, 4, 1, 16, 7, 5, 11, 9}中&#xff0c;数对之差的最大值是11&#xff0c;是16减去5的结果。 分治策略&#xff1a; 通常蛮力法不会是最好的解法&#xff0c…

Unity UGUI获取鼠标在屏幕的准确点击位置

想要获取鼠标在屏幕的准确点击位置&#xff0c;千万不要胡乱写&#xff0c;什么转化坐标系&#xff0c;什么Ray射线检测都是浮云。 1&#xff0c;转化坐标系只是相对而言&#xff0c;并不能准确实现当前鼠标点击在屏幕的位置&#xff1b; 2&#xff0c;Ray检测&#xff0c;hit是…

Numpy学习笔记(下篇)

目录 Numpy学习笔记&#xff08;下篇&#xff09;一、Numpy数组的合并与分割操作1、合并操作2、分割操作二、Numpy中的矩阵运算1、Universal Function2、矩阵运算3、向量和矩阵运算三、Numpy中的聚合操作四、Numpy中的arg运算1、索引操作2、排序和索引使用五、Fancy Indexing六…