Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def f():
greenlet.getcurrent().test = 42
def deldict(g):
def fmain(seen):
try:
greenlet.getcurrent().parent.switch()
except:
seen.append(sys.exc_info()[0])
raise
raise SomeError
def switchapply():
apply(greenlet.getcurrent().parent.switch, args, kwargs)
g = greenlet(switchapply)
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()
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():
def current_thread(default = None):
co = greenlet.getcurrent()
return _current_threads.get (co, default)
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
def greenlet_wrapper():
while True:
blk()
greenlet.getcurrent().parent.switch()
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()
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)