.
Disadvantages:
Unable to take advantage of multicore resources: The nature of the process is a single thread, it can not be a single CPU at the same time multiple cores, the process needs and processes to run on multi-CPU. Of course, most of the applications that we write in the day-out are not necessary, except for CPU-intensive applications.
Blocking (Blocking) operations (such as IO) can block the entire program
GeventGevent is a third-party library that makes it easy
entity of the program, in the modern thread-oriented computer architecture, the process is the container of the thread. A program is a description of the instruction, the data and its organization, and the process is the entity of the program. It contains the calls to various resources, the management of memory, the invocation of the network interface and so on. Third, what is the association process?Co-process, also known as micro-threading, fiber. English name Coroutine.The process looks like
The examples in this article describe Python coprocessor usage. Share to everyone for your reference. Specifically as follows:
The function is written as a task to handle a series of inputs sent to him, called a coprocessor.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14-15 16
def print_matchs (matchtext): print "Looking for", matchtext while true:line = (yield) #用 The yield statement and creates a c
connection pool to get the link #The future contains responseFuture =pool.submit (Task,url)#after the download succeeds, the Save method is called automaticallyFuture.add_done_callback (Save)Process1. Basic use fromMultiprocessingImportProcessImport TimedefTask (ARG): Time.sleep (ARG)Print(ARG)if __name__=='__main__': forIinchRange (10): P= Process (target=task,args=(i,)) P.daemon=True#P.daemon = FalseP.start ()#p.join (1)Print('The main process finally ...')2. Data sharing between proce
coprocessor, it can be interrupted at any time during the execution of a, and the execution of b,b may be interrupted during execution to execute a, and the result may be:12xy3zBut in a there is no call to B, so the call of the association is more difficult to understand than the function call.It seems that a, B's execution is a bit like multi-threading, but the process is characterized by a thread execution, and multithreading ratio, what is the adv
process, thread, coprocessor three brothers, those things.1. Threads
Definition: A thread is the smallest unit that the operating system can perform operations on.
Self-Understanding: Thread open, shared resources, thread is the system's call resource order, process is directly to the CPU, is CPU-based.
Feature decision usage (multithreading)
2. Process
Definition: A program cannot run on its own, only the p
more convenient way to switch than generator, when cutting to a task execution if you encounter Io, then blocking in place, still does not solve the problem of automatically switching to the IO to improve efficiency.The code for these 20 tasks for single-line thread usually has both a computational and a blocking operation, and we can get stuck in the execution of Task 1 o'clock and use the blocking time to perform the task so that we can improve efficiency, which uses the Gevent module.Iii. in
The process also has the advantage in I/O operations, the QT event loop, the ability to many I/O is already asynchronous, the use of good asynchronous (although all say async a little anti-human thinking).Because the CPU executes the smallest unit is the thread, the co-process is only on top of it and dispatched.I mean to take advantage of good async.The process is program-level scheduling, and there is no advantage for CPU execution.The smallest execution unit of the CPU is the thread, the sing
(r) print (' =================== ') #输出为9, the example above is equivalent to the following code Li = []for i in range] (Ten): def F1 (): return i li.append (F1)#li as a list, the inner element is the function of the same functionPrint (Li[0] ()) print (Li[1] ()) print (Li[2] ()) print (Li[3] ()) #输出: # 9# ===================# 9# 9# 9# 9Since the function is not executed when it is invoked, when the loop ends I is 9 and the last call is 9The above function can be printed with a sli
). The scheduler then reuses this thread for some and otherTask.What is the amount of memory that a task occupies in 9.Kilim?Here is a direct reference to the original text in the Kilim official document to answer:The amount of memory occupied by a task is:1. The Java object that represents the Task class2. If paused, an array of activation frames is stored. The KilimWeaver performs data flow and live variable and constant analysis(intra-procedurally) To ensure the IT capture only asMuch as is n
details, see: Explaining ' yield ' and ' generators ' (generator)III. Multi-process1, sub-process (subprocess package)In Python, fork a child process through the subprocess package, and run an external program.The OS module is the first to be considered when invoking the system's commands. Use Os.system () and Os.popen () to operate. However, these two commands are too simple to perform complex operations, such as providing input to a running command or reading the output of a command, judging
Process Lock2.4 Process Pool2.5 Summary3rd Chapter co-process3.1 Greenlet3.2 gevent3.3 Windows installation GeventImportqueueQ= queue. Queue (3) # define a queue for up to ten dataQ.put ( One) # putStoring dataQ.put ( A)Q.put ( -,Block=False, Timeout=2) # default block blocking, timeout time-outPrint(Q.qsize ())# Number of real dataPrint(Q.empty ())#to see if the queue is emptyPrint(Q.get ())Q.task_done ()#End Value TaskPrint(Q.get ())Q.task_done ()#End Value TaskPrint(Q.get (Block=False, Timeo
bit like recursion, is not feeling a little silly way?Indeed, this is not elegant, if not a good comment, it will let people can not touch the clue, the following is a very good way to achieve, that is to use the co-processIterator object used to get tokenpublic class Tokenverificationoperation:ienumerator {public bool MoveNext () {Debug.logger.Log (Isdown);Return! Isdown;}Public Tokenverificationoperation () {Zoneserverrequeset.sendportraittokenreq ();}public void Reset () {}public void Ontoke
between the Multiprocessing.dummy module and the multiprocessing module is that the dummy module is multi-threaded, and multiprocessing is multi-process, and the API is generic.Sometimes you see someone use Dummy,from. Multiprocessing.dummy Import Pool as ThreadPool as a thread pool. Its properties and methods can refer to the process pool. The above example can be changed in this way the code is as follows:frommultiprocessing.dummyimportpoolasthreadpoolif__name__== "__main__":urls=[ ' Http://
When you stop itself inside the process, the subsequent block of code continues to execute until the yield statement is encountered.Tested: Stopping the process means that the yield is stopped, so the statement after the yield is not executed after the process has been stopped.The code is as follows:1 usingUnityengine;2 usingSystem.Collections;3 4 Public classTest:monobehaviour {5 6 voidStart () {7Startcoroutine ("Method");8 }9 Ten IEnumerator Method () { OneStopcoroutine ("Method"); AD
paused, and whether the function stack frame has been saved. If it is pausing__no_state, indicating that the function is paused, the function has not saved the stack frame, you need to use this function stack frame, general subsequent execution of the required variables (including function arguments, function local variables) to the state, that is, Statestack[istack], Here is a list of the 4 possible states for a pausable method to complete:not_pausing__no_state = 0;Not_pausing__has_state = 1;P
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.