python- process & thread & coroutine

The old rules, first understand the concept

Von Neumann architecture:

  Input devices: keyboard, mouse

  Memory: Memory

  An output device: a display, a projector, a printer

 

 

 

Program: the file contains a piece of code is compiled

Process: The system by analyzing the file is loaded into memory object, the process is a resource allocation and scheduling basic unit (allocation cpu, allocated memory size, it is scheduled by the system), the process comprising instructions (if, for ...), data (variable, function ...), thread (he is also the thread of the container), he is the underlying operating system architecture.

Thread: real people who work in the process, the thread is resource scheduling smallest unit is a program minimum unit flow of execution, the thread contains the thread the above mentioned id , the current instruction pointer (thread switching, can continue to run again from the blocking position ), register set (thread switch, the result of this thread of execution to save), the stack after (the stack is advanced out perform a first function generating function object -> function push -> variable reference push -> calls the function -> pop stack, a thread of execution function is actually large piece of code, the target parameter from the thread can tell, it is a function of the received or the method)

process

Comment:

1: Each process consider themselves exclusive of all computer hardware resources ()

2: interprocess not share data (necessary to solve the problem of inter-process communication here)

Thread

Note: The top has largely talked about the thread, a thread here to tell you the characteristics

1: A process can have multiple threads, the same threads in the process shared data resources (here need to learn python in scope, because the python is used to control the scope of the process is to do a warm-up additional resources. , since there will be a shared resource thread-safety issues)

2: each thread has its own independent stack.

Several state of the thread (: 3 Ready : is not finished, nor a state in the middle of execution. Run : executing the code sheet. Clogging : it is waiting for the results of the processing system, such as in the implementation of the IO system. Terminate : complete execution or the exits or is canceled)

4: python thread no priority, no concept of thread group.

python- threaded development (threading library)

threading Properties and Methods

current_thread()

main_thread()

active_count()

enumerate()

get_ident

Thread class -> thread objects

Thread(target, name, args, kwargs)

The method of the Thread object

name

ident

is_alive()

Start: Start () and run () (start: the only way to start the thread run:. Is equivalent to a normal function call)

End: Python does not provide a method to terminate the thread (Thread 1 terminates: exception code appears sheet 2: complete execution thread 3: circular piece of code for a marker break the captured)

 

Coroutine

Guess you like

Origin www.cnblogs.com/wjj-/p/11802330.html