def __init__(self, name, parent, func, sim: Dependency('sim'), senslist=None, pargs=(), pkwargs={}, **kwargs): self.func = func self.senslist = senslist self.pargs = pargs self.pkwargs = pkwargs self.sim = sim if self.senslist is None: if func.__self__: # parent_name = '.'.join(self.name.split('.')[:-1]) # qname_intfs = {c.name: c for c in system.search(parent_name + '.*', of_type=Intf)} qname_intfs = { c.name: c for c in func.__self__.search(of_type=Intf) } intfs = {} for k, v in qname_intfs.items(): intfs[k.rsplit('.', 1)[1]] = v (inputs, outputs) = getio_vars(func, intfs=intfs) self.senslist = inputs - outputs self._exit_func = None self.sim.proc_reg(self) greenlet.__init__(self)
def __init__(self, threadpool): # Construct in the main thread (owner of the threadpool) # The parent greenlet and thread identifier will be set once the # new thread begins running. RawGreenlet.__init__(self) self._hub = threadpool.hub # Avoid doing any imports in the background thread if it's not # necessary (monkey.get_original imports if not patched). # Background imports can hang Python 2 (gevent's thread resolver runs in the BG, # and resolving may have to import the idna module, which needs an import lock, so # resolving at module scope) if monkey.is_module_patched('sys'): stderr = monkey.get_original('sys', 'stderr') else: stderr = sys.stderr self._stderr = stderr # We can capture the task_queue; even though it can change if the threadpool # is re-innitted, we won't be running in that case self._task_queue = threadpool.task_queue # type:gevent._threading.Queue self._task_queue_cookie = self._task_queue.allocate_cookie() self._unregister_worker = threadpool._unregister_worker threadpool._register_worker(self) try: start_new_thread(self._begin, ()) except: self._unregister_worker(self) raise
def __init__(self, sim): self.simulator = sim self.name = 'Scheduler' greenlet.__init__(self) configurator = RequiredVariable('Configurator') if configurator['sys.scheduler', 'log_task_switching', False]: self.settrace(self.callback)
def __init__(self, threadpool): RawGreenlet.__init__(self, threadpool._worker) self.thread_ident = get_thread_ident() self._threadpool_wref = wref(threadpool) # Inform the gevent.util.GreenletTree that this should be # considered the root (for printing purposes) and to # ignore the parent attribute. (We can't set parent to None.) self.greenlet_tree_is_root = True self.parent.greenlet_tree_is_ignored = True
def __init__(self, loop=None, default=None): greenlet.__init__(self) if default is not None: raise DeprecationWarning("default is deprecated") if hasattr(loop, 'run_forever'): self.loop = loop else: self.loop = get_event_loop() self._resolver = None self._threadpool = None self.format_context = _import(self.format_context)
def __init__(self, hub, run=None, *args, **kwargs): greenlet.__init__(self, parent=hub._greenlet) if run is not None: self._run = run self.hub = hub self.args = args self.kwargs = kwargs self._links = deque() self.value = None self._exception = _NONE self._notifier = None self._start_event = None
def __init__(self, function, parent): greenlet.__init__(self, function, parent) # See greenlet.py's Greenlet class. We capture the cheap # parts to maintain the tree structure, but we do not capture # the stack because that's too expensive for 'spawn_raw'. current = getcurrent() # pylint:disable=undefined-variable self.spawning_greenlet = wref(current) # See Greenlet for how trees are maintained. try: self.spawn_tree_locals = current.spawn_tree_locals except AttributeError: self.spawn_tree_locals = {} if current.parent: current.spawn_tree_locals = self.spawn_tree_locals
def __init__(self, loop=None, default=None): greenlet.__init__(self) if hasattr(loop, 'run'): if default is not None: raise TypeError("Unexpected argument: default") self.loop = loop else: if default is None and get_ident() != MAIN_THREAD: default = False loop_class = _import(self.loop_class) if loop is None: loop = self.backend self.loop = loop_class(flags=loop, default=default) self._resolver = None self._threadpool = None self.format_context = _import(self.format_context)
def __init__(self, module, func, *args, exit_func=None, **kwargs): self.func = func self.func_params = kwargs self.module = module self.arch = self.module.current_arch self.module.proc_reg(self) self.name = module.qualified_name + "." + func.__name__ senslist = [] for a in args: if hasattr(a, 'subscribe'): senslist.append(a) self.senslist = senslist self._exit_func = exit_func # If the module is to be traslated to HDL, translate the process if module.hdl_gen: self.hdl_gen() greenlet.__init__(self)
def __init__(self, loop=None, default=None): greenlet.__init__(self) if hasattr(loop, 'run'): if default is not None: raise TypeError("Unexpected argument: default") self.loop = loop elif _threadlocal.loop is not None: # Reuse a loop instance previously set by # destroying a hub without destroying the associated # loop. See #237 and #238. self.loop = _threadlocal.loop else: if default is None and get_ident() != MAIN_THREAD: default = False loop_class = _import(self.loop_class) if loop is None: loop = self.backend self.loop = loop_class(flags=loop, default=default) self._resolver = None self._threadpool = None self.format_context = _import(self.format_context)
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
def __init__(self, run=None, *args, **kwargs): # pylint:disable=keyword-arg-before-vararg """ 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
def __init__(self, name, parent, func, sim : Dependency('sim'), senslist=None, pargs = (), pkwargs = {}, **kwargs): self.func = func self.senslist = senslist self.pargs = pargs self.pkwargs = pkwargs self.sim = sim if self.senslist is None: if func.__self__: # parent_name = '.'.join(self.name.split('.')[:-1]) # qname_intfs = {c.name: c for c in system.search(parent_name + '.*', of_type=Intf)} qname_intfs = {c.name: c for c in func.__self__.search(of_type=Intf)} intfs = {} for k,v in qname_intfs.items(): intfs[k.rsplit('.', 1)[1]] = v (inputs, outputs) = getio_vars(func, intfs=intfs) self.senslist = inputs - outputs self._exit_func = None self.sim.proc_reg(self) greenlet.__init__(self)
def __init__(self, loop): self.loop = loop greenlet.__init__(self)
def __init__(self): greenlet.__init__(self) self.count = 0
def __init__(self, hub): greenlet.__init__(self, parent=hub.parent) self.hub = hub
def __init__(self, log_task_switching=False): greenlet.__init__(self) if log_task_switching: self.settrace(self.callback)
def __init__(self, fn: Callable[..., Any], driver: greenlet): greenlet.__init__(self, fn, driver) self.driver = driver if _has_gr_context: self.gr_context = driver.gr_context
def __init__(self, fn: Callable[..., Any], driver: greenlet): greenlet.__init__(self, fn, driver) self.driver = driver if _copy_context is not None: self.gr_context = _copy_context()