How to use the greenlet.greenlet.getcurrent function in greenlet

To help you get started, we’ve selected a few greenlet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-greenlet / greenlet / tests / test_greenlet.py View on Github external
def f():
            greenlet.getcurrent().test = 42
        def deldict(g):
github python-greenlet / greenlet / tests / test_greenlet.py View on Github external
def fmain(seen):
    try:
        greenlet.getcurrent().parent.switch()
    except:
        seen.append(sys.exc_info()[0])
        raise
    raise SomeError
github python-greenlet / greenlet / tests / test_greenlet.py View on Github external
def switchapply():
                apply(greenlet.getcurrent().parent.switch, args, kwargs)
            g = greenlet(switchapply)
github python-greenlet / greenlet / tests / test_greenlet.py View on Github external
greenlet.getcurrent() # update ts_current
                lock2.release() # release gc
            t = threading.Thread(target=another_thread)
            t.start()
            class gc_callback(object):
                def __del__(self):
                    lock1.release()
                    lock2.acquire()
                    recycled[0] = True
            class garbage(object):
                def __init__(self):
                    self.cycle = self
                    self.callback = gc_callback()
            l = []
            x = range(N*2)
            current = greenlet.getcurrent()
            g = garbage()
            for i in x:
                g = None # lose reference to garbage
                if recycled[0]:
                    # gc callback called prematurely
                    t.join()
                    return False
                last = greenlet()
                if recycled[0]:
                    break # yes! gc called in green_new
                l.append(last) # increase allocation counter
            else:
                # gc callback not called when expected
                gc.collect()
                if recycled[0]:
                    t.join()
github python-greenlet / greenlet / tests / test_greenlet.py View on Github external
def worker():
            # wait for the value
            value = greenlet.getcurrent().parent.switch()
            # delete all references to ourself
            del worker[0]
            initiator.parent = greenlet.getcurrent().parent
            # switch to main with the value, but because
            # ts_current is the last reference to us we
            # return immediately
            try:
                greenlet.getcurrent().parent.switch(value)
            finally:
                seen.append(greenlet.getcurrent())
        def initiator():
github slideinc / gogreen / gogreen / coro.py View on Github external
def current_thread(default = None):
    co = greenlet.getcurrent()
    return _current_threads.get (co, default)
github cornell-brg / pymtl / pclib / fl / BytesMemPortAdapter.py View on Github external
s.memreq.val.next  = 1
    s.memresp.rdy.next = 1

    while not s.memreq.rdy:
      s.trace = ";"
      greenlet.getcurrent().parent.switch(0)

    # If memory response has not arrived, then yield

    s.memreq.val.next  = 0
    s.memresp.rdy.next = 1

    while not s.memresp.val:
      s.trace = ":"
      greenlet.getcurrent().parent.switch(0)

    # When memory response has arrived, then we are done

    s.trace = " "
    s.memreq.val.next  = 0
    s.memresp.rdy.next = 0
github cornell-brg / pymtl3 / pymtl3 / passes / sim / WrapGreenletPass.py View on Github external
def greenlet_wrapper():
        while True:
          blk()
          greenlet.getcurrent().parent.switch()
github sim-x / simx / simx / processmgr.py View on Github external
is put to sleep indefinitely till woken up by the
        main thread
        """
        #util.check_type(process.Process, proc)
        proc_info = self.proc_table[id(proc)]
        if proc_info.status_ != ProcStatus._active:
            ds.failure.write("ProcessManager: Invalid State for process ", 
                             proc.__class__.__name__,
                             " Cannot sleep a process that is not active")
        if duration is not None:
            msg = _ProcWakeUpMsg( pid = id(proc) )
            self.send_to_self( msg, duration )
        proc_info.status_ = ProcStatus._sleep
        #Notethe statement below has no effect if its called from within main greenlet
        if switch == True:
            greenlet.getcurrent().parent.switch() 
github cornell-brg / pymtl / pymtl / tools / simulation / sim_utils.py View on Github external
def inner_wrapper():
    while True:

      # Call the tick function

      func()

      # Yield so we always only do one tick per cycle

      greenlet.greenlet.getcurrent().parent.switch(0)