Replace the standard :mod:`thread` module to make it greenlet-based.
    If *threading* is true (the default), also patch ``threading``.
    If *_threading_local* is true (the default), also patch ``_threading_local.local``.
192662
def patch_thread(threading=True, _threading_local=True, Queue=True, Event=False):
    
    monkey.patch_module('thread')
    if threading:
        monkey.patch_module('threading')
        threading = __import__('threading')
        if Event:
            from gevent.event import Event
            threading.Event = Event
        if Queue:
            from gevent import queue
            threading.queue = queue
    if _threading_local:
        _threading_local = __import__('_threading_local')
        from gevent.local import local
        _threading_local.local = local
445824
def greenlet_report(self):
        

        self.report_worker(w=1)
        while True:
            try:
                self.report_worker()
            except Exception as e:  # pylint: disable=broad-except
                self.log.error("When reporting: %s" % e)
            finally:
                time.sleep(self.config["report_interval"])
1146819
def join(self):
        """"""
        self.closed = True

        while self.expect > 0:
            val = self.wait_change.get()
            self.expect -= 1

            if val is not None:
                # Wait a while for all running greenlets to exit, and
                # then attempt to force them to exit so join()
                # terminates in a reasonable amount of time.
                gevent.joinall(list(self.greenlets), timeout=30)
                gevent.killall(list(self.greenlets), block=True, timeout=30)
                raise val
1297114
def _remove_dead_greenlet(self, task_name):
        '''
        
        '''
        for greenlet in self.active[task_name]:
            try:
                # Allows active greenlet continue to run
                if greenlet.dead:
                    self.active[task_name].remove(greenlet)
            except BaseException:
                pass
859774
def get(self, thread=None, plugin=None):
        
        if plugin is not None:
            if thread is None:
                threads_list = {}
                for key in self.threads.keys():
                    if self.threads[key].plugin == plugin:
                        threads_list[key] = self.threads[key]
                return threads_list
            else:
                if thread in self.threads.keys():
                    if self.threads[thread].plugin == plugin:
                        return self.threads[thread]
                    else:
                        return None
                else:
                    return None
        else:
            if thread is None:
                return self.threads
            else:
                if thread in self.threads.keys():
                    return self.threads[thread]
                else:
                    return None
928653
def use_gae_thread():
    """"""
    global _THREAD_CLASS  # pylint: disable=global-statement
    try:
        from google.appengine.api.background_thread import background_thread
        _THREAD_CLASS = background_thread.BackgroundThread
    except ImportError:
        _logger.error(
            u'Could not install appengine background threads!'
            u' Please install the python AppEngine SDK and use this from there')
1211702
def local_property():
    
    ls = local()

    def fget(self):
        try:
            return ls.var
        except AttributeError:
            raise RuntimeError("Request context not initialized.")

    def fset(self, value):
        ls.var = value

    def fdel(self):
        del ls.var

    return property(fget, fset, fdel, 'Thread-local property')
708886
def newthread(template="EPCThread-{0}", **kwds):
    
    if not isinstance(template, str):
        template = '{0}.{1}-{{0}}'.format(template.__module__,
                                          template.__class__.__name__)
    return threading.Thread(
        name=newname(template), **kwds)
622968
def update_native_thread_name
      thread = JRuby.reference(Thread.current)
      set_thread_name = Proc.new do |prefix, suffix|
        self.class.with_global_lock do
          count = self.class.system_registered_workers.size
          thread.native_thread.name = "#{prefix}##{count}#{suffix}"
        end
      end
      if ! name = thread.native_thread.name
        # "#{THREAD_ID}##{count}" :
        set_thread_name.call(WORKER_THREAD_ID, nil)
      elsif ! name.index(WORKER_THREAD_ID)
        # "#{name}(#{THREAD_ID}##{count})" :
        set_thread_name.call("#{name} (#{WORKER_THREAD_ID}", ')')
      end
    end
1013640
def get_current_context_id():
    
    global get_current_context_id
    if greenlet is not None:
        if stackless is None:
            get_current_context_id = greenlet.getcurrent
            return greenlet.getcurrent()
        return greenlet.getcurrent(), stackless.getcurrent()
    elif stackless is not None:
        get_current_context_id = stackless.getcurrent
        return stackless.getcurrent()
    get_current_context_id = _thread.get_ident
    return _thread.get_ident()
196308
function(context, request, callback){
		if ((context.indexOf('node_modules') !== -1) || (request.indexOf('.') !== 0)) {
			callback(null, 'commonjs ' + request);
		}
		else {
			callback();
		}
	}
1021523
def threaded(func):
    

    def dec(self, *args, **kwargs):
        thread.start_new_thread(func, (self, ) + args, kwargs)

    return dec
920
def thread_data(name, value=NOTHING, ct=None):
    '''
    '''
    ct = ct or current_thread()
    if is_mainthread(ct):
        loc = process_data()
    elif not hasattr(ct, '_pulsar_local'):
        ct._pulsar_local = loc = {}
    else:
        loc = ct._pulsar_local
    if value is not NOTHING:
        if name in loc:
            if loc[name] is not value:
                raise RuntimeError(
                    '%s is already available on this thread' % name)
        else:
            loc[name] = value
    return loc.get(name)
1193669
def _threaded_start(self):
        '''
        
        '''
        self.active = True
        self.thread = Thread(target=self._main_loop)
        self.thread.setDaemon(True)
        self.thread.start()
294267
def push_thread_local_value(name, value) #:nodoc:
      save_val = thread_local_value(name)
      set_thread_local_value(name, value)
      begin
        yield
      ensure
        set_thread_local_value(name, save_val)
      end
    end
557703
def run_on_ui_thread(f):
    '''
    '''
    def f2(*args, **kwargs):
        Runnable(f)(*args, **kwargs)
    return f2
336136
def add_greenlet_name(
        _logger: str,
        _method_name: str,
        event_dict: Dict[str, Any],
) -> Dict[str, Any]:
    """"""
    current_greenlet = gevent.getcurrent()
    greenlet_name = getattr(current_greenlet, 'name', None)
    if greenlet_name is not None and not greenlet_name.startswith('Greenlet-'):
        event_dict['greenlet_name'] = greenlet_name
    return event_dict