Skip to content

Instantly share code, notes, and snippets.

@mickeprag
Last active August 21, 2018 09:46
Show Gist options
  • Save mickeprag/75a0fbf04cfd06c3fe48b759da22f5ef to your computer and use it in GitHub Desktop.
Save mickeprag/75a0fbf04cfd06c3fe48b759da22f5ef to your computer and use it in GitHub Desktop.
from lupa import LuaRuntime
script = """
function callDone(response)
end
function run(arg)
http:get(callDone)
end
"""
class Request(object):
def get(self, success):
return PendingRequest(success)
class PendingRequest(object):
def __init__(self, callback):
super(PendingRequest,self).__init__()
self.callback = callback
lua = LuaRuntime()
lua.globals().http = Request()
lua.execute(script)
fn = getattr(lua.globals(), 'run')
for i in range(10000):
print("Start call", i)
thread = fn.coroutine()
try:
thread.send(None)
except StopIteration:
pass
print("Wait for shutdown")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment