Skip to content

Instantly share code, notes, and snippets.

@ionrock

ionrock/cli.py Secret

Created February 8, 2016 14:45
import thread
import json
import time
import eventlet
from eventlet import tpool
from taskflow import engines
from taskflow import task
from taskflow.patterns import linear_flow
class ListTargets(task.Task):
default_provides = 'targets'
def execute(self):
time.sleep(5)
return 'yeah'
def make_flow():
flow = linear_flow.Flow('exp')
flow.add(ListTargets())
return flow
def run_flow(tid):
print('tid: %s' % tid)
flow = make_flow()
result = engines.run(flow, engine='serial', store={})
return result
def listen(client):
while True:
c = client.recv(1)
if not c:
break
result = tpool.execute(run_flow, thread.get_ident())
print(result)
client.sendall(json.dumps(result))
def main():
server = eventlet.listen(('0.0.0.0', 6000))
pool = eventlet.GreenPool(10000)
while True:
new_sock, address = server.accept()
pool.spawn_n(listen, new_sock)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment