Skip to content

Instantly share code, notes, and snippets.

@ionrock

ionrock/cli.py Secret

Created February 8, 2016 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionrock/ece1962f513e5f70baba to your computer and use it in GitHub Desktop.
Save ionrock/ece1962f513e5f70baba to your computer and use it in GitHub Desktop.
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):
n = 1
for i in range(1000):
n = n * i + 1
return n
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