Python--eventlet.greenthread

Source: Internet
Author: User
Tags stack trace

The module implements the "Green thread" in Eventlet, which is the co-process.

An introduction to the relevant Greenlet modules.

Directory

One, module-level functions

Sleep ()

Spawn ()

    

Module-level functions

  

eventlet.greenthread.sleep (seconds=0)

  
Give control after at least the parameter seconds seconds, the parameter seconds can be an integer, but also a floating-point type. When the parameter seconds is 0 o'clock, the initiative gives control, which is useful when performing a long calculation to allow other processes to be executed.
  
Eventlet.greenthread.spawn (func, *args, **kwargs)
  
Hatch (Create) a *args that can call func ( **kwargs), return a greenthread object that can be used to get called func (*args, * * The return value of the Kwargs).
After this instruction is executed, the control immediately returns to the function calling the interface, and the creation of the co-process only has the ability to invoke func (*args, **kwargs) , instead of hatching here, the coprocessor immediately calls func (*args, **kwargs). spawn_after () can specify that a co-process is hatched after a certain amount of time.
  
Eventlet.greenthread.spawn_n (func, *args, **kwargs)
  
Hatching (creating) a *args that can call func ( **kwargs), where the returned coprocessor cannot get the return value of func (*args, **kwargs) or throws an exception, than Spawn ( ) is faster, and the command runs fastest when there are no keyword parameters.
If the function throws an exception, Spawn_n prints the stack trace, which can be turned off by Eventlet.debug.hub_exceptions () .
  
eventlet.greenthread.spawn_after (seconds, Func, *args, **kwargs)
  
Parameter seconds seconds to hatch a coprocessor that can invoke func . returns a greenthread object that can be used to get the return value of the calling func .
  
eventlet.greenthread.spawn_after_local (seconds, Func, *args, **kwargs)
  
seconds seconds after the incubation process, if the current association exits, then the function will not be called. The seconds can be an integer or a floating-point number, and the parameter func executes in its own process, and the arguments passed to it are just args and Kwargs.
Returns a Greenthread object that can get the return value of func .
  
Greenthread Object
  
class Eventlet.greenthread.GreenThread (parent)
  
   The Greenthread class is a subclass of Greenlet, adding the ability to get the return value of the main function, instead of constructing the Greenthread object directly, and using the spawn () function to hatch a new process!
  
Cancel (*throw_args)
  
If the process is not yet running, it is equivalent to killing it, and if the coprocessor is already running, it will wait for it to run and then kill it. Once this function is called, all wait () calls will throw an exception throw_args (the default is Greenlet. Greenletexit ).
  
Kill (*throw_args)
  
Forced to kill the association, even if the function inside the process has been run to kill it. Once this function is called, all Wait () calls will throw an exception Throw_args (the default is Greenlet. Greenletexit).
  
Link (func, *curried_args, **curried_kwargs)
  
Establishes a function func , which is invoked with the result of the current process.
The function func should have the following signature:
def func (GT, [curried Args/kwargs]):

When the process is complete, it invokes func immediately, passing itself along with curried arguments to func . If func wants to get the return value of the co-process, it should call the first argument, that is, the wait () method that calls its own thread.
func runs in the context of calling its own, so it is possible to interfere with other connected functions, such as by explicitly switching to other threads.
unlink (func, *curried_args, **curried_kwargs)
  
removed from the link () function sets the connection and returns False if successful returns True .
  
Wait ()
  
Returns the execution result of the main function in the current process, and if it is a generic execution result,wait () returns it, and if it is an exception,wait () throws the same exception (but the stack trace inevitably contains frames in some of the co-modules).

Python--eventlet.greenthread

Related Article

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.