Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #52, stops iteration when client disconnects #53

Merged
merged 3 commits into from
Mar 29, 2017

Conversation

algrebe
Copy link
Contributor

@algrebe algrebe commented Mar 27, 2017

for the same script in issue #52

import time
from funcserver import Server

class MyAPI(object):
    def foo(self):
        try:
            self.log.info("starting...")
            for i in xrange(10):
                self.log.info("yielding", i=i)
                yield i
                time.sleep(2.0)

        finally:
            self.log.info("cleanup...")

class MyServer(Server):
    def prepare_api(self):
        return MyAPI()

if __name__ == '__main__':
    MyServer().start()
python test.py run --port 8888
$ curl 'http://localhost:8888/rpc/json?fn=foo'
0
1
2
^C

When client disconnects, stops iteration midway and performs cleanup

2017-03-27T10:16:29.238897Z [info     ] starting...                    _={'ln': 7, 'file': 'test.py', 'name': '__main__', 'fn': 'foo'}
2017-03-27T10:16:29.239013Z [info     ] yielding                       _={'ln': 9, 'file': 'test.py', 'name': '__main__', 'fn': 'foo'} i=0
2017-03-27T10:16:29.654906Z [info     ] api,fn=foo,host=ant-Dell-n411z,name=FuncServer,success=True c_invoked=1,t_duration_count=1,t_duration_lower=0.0100135803223,t_duration_mean=0.0100135803223,t_duration_sum=0.0100135803223,t_duration_upper=0.0100135803223 1490609789654 influx_metric=True
2017-03-27T10:16:31.241505Z [info     ] yielding                       _={'ln': 9, 'file': 'test.py', 'name': '__main__', 'fn': 'foo'} i=1
2017-03-27T10:16:33.244503Z [info     ] yielding                       _={'ln': 9, 'file': 'test.py', 'name': '__main__', 'fn': 'foo'} i=2
2017-03-27T10:16:35.247424Z [info     ] yielding                       _={'ln': 9, 'file': 'test.py', 'name': '__main__', 'fn': 'foo'} i=3
2017-03-27T10:16:35.263030Z [info     ] cleanup...                     _={'ln': 14, 'file': 'test.py', 'name': '__main__', 'fn': 'foo'}
2017-03-27T10:16:35.263346Z [info     ] 200 GET /rpc/json?fn=foo (127.0.0.1) 6026.45ms _={'ln': 1971, 'file': '~/.virtualenvs/funcserver/local/lib/python2.7/site-packages/tornado/web.py', 'name': 'tornado.access', 'fn': 'log_request'}
2017-03-27T10:16:41.106105Z [warning  ] exited via keyboard interrupt  _={'ln': 64, 'file': '~/.virtualenvs/funcserver/local/lib/python2.7/site-packages/basescript/basescript.py', 'name': 'basescript.basescript', 'fn': 'start'}

handles the StreamClosedError raised when flushing data
after the client has disconnected.
@algrebe algrebe merged commit bc9d5df into deep-compute:master Mar 29, 2017
@algrebe algrebe deleted the funcserver-iter-leak branch March 29, 2017 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants