The content of this section
- process, and thread differences
- Python Gil Global Interpreter lock
- Thread
- Grammar
- Join
- Lock\rlock\ signal volume of the thread lock
- Turning Threads into daemons
- Event Events
- Queue queues
- Producer Consumer Model
- Queue queues
- Develop a thread pool
- Process
- Grammar
- Inter-process communication
- Process Pool
ssh ssh_sftp ssh key Rsh-Asymmetric key authentication Public key: Publicly key private key: Privat key 10.0.0.31-- --Connect----> 10.0.0.41 private key 10.0.0.31 generate key pair ssh-keygen Process and Thread threads: (a bunch of instructions) is the OS operating system to dispatch CPU operation of the smallest unit process: a collection of resources, do not have the properties to execute, to operate the CPU, you must first create a thread. ---> A process that contains at least one thread (the main path) to execute: For example, QQ is a process, thread 4, the same process can be exchanged between different threads; two processes want to communicate through an intermediary agent 5, a thread can control and manipulate other threads in the same process, but the process can only manipulate sub-processes storage speed: CPU > Memory > Files One program cannot access another program: The program is a process, and two processes cannot access each other eg. : Start 50 threads at once, unify the final result: the solution: first create a temporary list, add all the results, and then loop the list import Threadingimport time #一, call start_time =time.time directly () T_obj = []def run (N):p rint ("Hello", N) time.sleep (2) for I in range: t= Threading. Thread (Target=run, args= ("t-%s"%i,)) T.start () t_obj.append (t) for T in T_obj:t.join () print ("t-%s have finished ... "%i) print (" Cost Time: ", Time.time ()-start_time) print (" Well done!! ") threading.current_thread () #查看进程类型threading. Active_count () #查看活动的线程 Daemon (daemon thread): dependent on the main thread to survive, the main process is finished, all the daemons are followed by the end, the program exits. gil Lock User Lock Recursive lock Rlock: Multilevel lock anti-lock dead semaphore (semaphore) Import Threading,time def Run (n): Semaphore.acquire () Time.sleep (1) print ("Run the Thread:%s"%n) semaphore.release () if __name__ = = "__main__": semaphore = Threading. Boundedsemaphore (5) #最多同时允许5个线程同时运行for I in range: T =threading. Thread (target=run,args= (i,)) T.start () while threading.active_count ()!=1:p asselse:print ("---all Threads done- --") Advantages: 1, decoupling of the program 2, improve efficiency
Python Growth notes-Basic (10)