예제 #1
0
    def __init__(self, run=None, *args, **kwargs):
        """
        Greenlet constructor.

        :param args: The arguments passed to the ``run`` function.
        :param kwargs: The keyword arguments passed to the ``run`` function.
        :keyword run: The callable object to run. If not given, this object's
            `_run` method will be invoked (typically defined by subclasses).

        .. versionchanged:: 1.1a3
            The ``run`` argument to the constructor is now verified to be a callable
            object. Previously, passing a non-callable object would fail after the greenlet
            was spawned.
        """
        hub = get_hub()
        greenlet.__init__(self, parent=hub)
        if run is not None:
            self._run = run

        # If they didn't pass a callable at all, then they must
        # already have one. Note that subclassing to override the run() method
        # itself has never been documented or supported.
        if not callable(self._run):
            raise TypeError("The run argument or self._run must be callable")

        if args:
            self.args = args
        if kwargs:
            self._kwargs = kwargs
예제 #2
0
    def __init__(self, run=None, *args, **kwargs):
        """
        Greenlet constructor.

        :param args: The arguments passed to the ``run`` function.
        :param kwargs: The keyword arguments passed to the ``run`` function.
        :keyword run: The callable object to run. If not given, this object's
            `_run` method will be invoked (typically defined by subclasses).

        .. versionchanged:: 1.1a3
            The ``run`` argument to the constructor is now verified to be a callable
            object. Previously, passing a non-callable object would fail after the greenlet
            was spawned.
        """
        hub = get_hub()
        greenlet.__init__(self, parent=hub)
        if run is not None:
            self._run = run

        # If they didn't pass a callable at all, then they must
        # already have one. Note that subclassing to override the run() method
        # itself has never been documented or supported.
        if not callable(self._run):
            raise TypeError("The run argument or self._run must be callable")

        if args:
            self.args = args
        if kwargs:
            self._kwargs = kwargs
예제 #3
0
파일: greenlet.py 프로젝트: 3ddi/gevent
 def __init__(self, run=None, *args, **kwargs):
     hub = get_hub()
     greenlet.__init__(self, parent=hub)
     if run is not None:
         self._run = run
     if args:
         self.args = args
     self.kwargs = kwargs
예제 #4
0
 def __init__(self, run=None, *args, **kwargs):
     hub = get_hub()
     greenlet.__init__(self, parent=hub)
     if run is not None:
         self._run = run
     if args:
         self.args = args
     self.kwargs = kwargs
 def __init__(self, run=None, *args, **kwargs):
     greenlet.__init__(self, parent=get_hub())
     if run is not None:
         self._run = run
     self.args = args
     self.kwargs = kwargs
     self._links = []
     self.value = None
     self._exception = _NONE
     self._notifier = None
     self._start_event = None
예제 #6
0
 def __init__(self, run=None, *args, **kwargs):
     greenlet.__init__(self, parent=get_hub())
     if run is not None:
         self._run = run
     self.args = args
     self.kwargs = kwargs
     self._links = []
     self.value = None
     self._exception = _NONE
     self._notifier = None
     self._start_event = None
예제 #7
0
 def __init__(self, run=None, *args, **kwargs):
     hub = get_hub()
     greenlet.__init__(self, parent=hub)
     if run is not None:
         self._run = run
     self.args = args
     self.kwargs = kwargs
     self._links = deque()
     self.value = None
     self._exception = _NONE
     loop = hub.loop
     self._notifier = loop.callback()
     self._start_event = None
예제 #8
0
 def __init__(self, run=None, *args, **kwargs):
     hub = get_hub()
     greenlet.__init__(self, parent=hub)
     if run is not None:
         self._run = run
     self.args = args
     self.kwargs = kwargs
     self._links = deque()
     self.value = None
     self._exception = _NONE
     loop = hub.loop
     self._notifier = None
     self._start_event = None
예제 #9
0
 def __init__(self, run=None, *args, **kwargs):
     greenlet.__init__(self, parent=get_hub())
     if run is not None:
         def wrap(*a,**b):
             sys.settrace(threading._trace_hook)
             return run(*a,**b)
         self._run = wrap
     self.args = args
     self.kwargs = kwargs
     self._links = []
     self.value = None
     self._exception = _NONE
     self._notifier = None
     self._start_event = None
예제 #10
0
파일: greenlet.py 프로젝트: SMFOSS/gevent
 def __init__(self, run=None, *args, **kwargs):
     greenlet.__init__(self, parent=get_hub())
     if run is not None:
         self._run = run
     if args:
         self.args = args
     if kwargs:
         self.kwargs = kwargs
     self._links = set()
     self.value = None
     self._exception = _NONE
     self._notifier = None
     self._start_event = None
     group = getattr(getcurrent(), "group", None)
     if group is not None:
         self.group = group
         group.add(self)
예제 #11
0
파일: greenlet.py 프로젝트: vhnuuh/pyutil
    def __init__(self, run=None, *args, **kwargs):
        """
        Greenlet constructor.

        :param args: The arguments passed to the ``run`` function.
        :param kwargs: The keyword arguments passed to the ``run`` function.
        :keyword run: The callable object to run. If not given, this object's
            `_run` method will be invoked (typically defined by subclasses).

        .. versionchanged:: 1.1b1
            The ``run`` argument to the constructor is now verified to be a callable
            object. Previously, passing a non-callable object would fail after the greenlet
            was spawned.
        """
        # greenlet.greenlet(run=None, parent=None)
        # Calling it with both positional arguments instead of a keyword
        # argument (parent=get_hub()) speeds up creation of this object ~30%:
        # python -m timeit -s 'import gevent' 'gevent.Greenlet()'
        # Python 3.5: 2.70usec with keywords vs 1.94usec with positional
        # Python 3.4: 2.32usec with keywords vs 1.74usec with positional
        # Python 3.3: 2.55usec with keywords vs 1.92usec with positional
        # Python 2.7: 1.73usec with keywords vs 1.40usec with positional
        greenlet.__init__(self, None, get_hub())

        if run is not None:
            self._run = run

        # If they didn't pass a callable at all, then they must
        # already have one. Note that subclassing to override the run() method
        # itself has never been documented or supported.
        if not callable(self._run):
            raise TypeError("The run argument or self._run must be callable")

        if args:
            self.args = args
        if kwargs:
            self._kwargs = kwargs
예제 #12
0
    def __init__(self, run=None, *args, **kwargs):
        """
        Greenlet constructor.

        :param args: The arguments passed to the ``run`` function.
        :param kwargs: The keyword arguments passed to the ``run`` function.
        :keyword run: The callable object to run. If not given, this object's
            `_run` method will be invoked (typically defined by subclasses).

        .. versionchanged:: 1.1b1
            The ``run`` argument to the constructor is now verified to be a callable
            object. Previously, passing a non-callable object would fail after the greenlet
            was spawned.
        """
        # greenlet.greenlet(run=None, parent=None)
        # Calling it with both positional arguments instead of a keyword
        # argument (parent=get_hub()) speeds up creation of this object ~30%:
        # python -m timeit -s 'import gevent' 'gevent.Greenlet()'
        # Python 3.5: 2.70usec with keywords vs 1.94usec with positional
        # Python 3.4: 2.32usec with keywords vs 1.74usec with positional
        # Python 3.3: 2.55usec with keywords vs 1.92usec with positional
        # Python 2.7: 1.73usec with keywords vs 1.40usec with positional
        greenlet.__init__(self, None, get_hub())

        if run is not None:
            self._run = run

        # If they didn't pass a callable at all, then they must
        # already have one. Note that subclassing to override the run() method
        # itself has never been documented or supported.
        if not callable(self._run):
            raise TypeError("The run argument or self._run must be callable")

        if args:
            self.args = args
        if kwargs:
            self._kwargs = kwargs