Python Growth Notes-basics (10)

Source: Internet
Author: User

The content of this section
    1. process, and thread differences
    2. Python Gil Global Interpreter lock
    3. Thread
      1. Grammar
      2. Join
      3. Lock\rlock\ signal volume of the thread lock
      4. Turning Threads into daemons
      5. Event Events
      6. Queue queues
      7. Producer Consumer Model
      8. Queue queues
      9. Develop a thread pool
    1. Process
      1. Grammar
      2. Inter-process communication
      3. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.