Skip to content

Commit

Permalink
multiprocessing removed and concurrent futures is used to support bul…
Browse files Browse the repository at this point in the history
…k queries
  • Loading branch information
RamanjaneyuluIdavalapati committed May 11, 2018
1 parent b4416d4 commit 65b469e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ deploy:
skip_cleanup: true
api_key:
secure: 3wIm6vrNmdIP50NIUtig33S34FonRqxGnRRY55oiMN4BD5xeo2iQb8TmWMswwqVTuO09C3Cd7kBxP5JxBR+dCuVZZRqpL/8E6JUTaGyZcQ/9HgB8FwYXRCj2ASPDHfmjmZ8F3GIX19akJLKiTThB1WU3XidcZ9tZgwvOmf10Jy7IXiddRKwucVVVy608H9hUXPpIVMzqcFfeU2KeXcotU0J2eZyqso/RCPNw4qDZKFvkiKT2MM4B6FgY7WYorNUW1JXdh8dcAV7vb0oNB0iUNLMCpNHFqoyfOHcxKUgP81wMS8TY5wWLuQxUESg1eyo7Q9gwegOseySU1NBjlPyltVVWtulltM2sge0KgVoLgQRia/LeKnCynSi2r8aic1VoMUDEH5ZfWuJJrFHOJyKCNapp3MKK42UXDo28NpdjjUUgJOOukWpXsaVmPhPXpWWQlZM9YMeMPxTUpm3ZACs2WmHssVwO7EaTaJ45ctAf4m0csb7Ri5IyR5iLy9YEX6fuNMoNVCI6lE7ax38pf1mkgamZTJtvEFr+ekKMXq3heVk598rA2P7hzI5Z6Zx7S8GyQz4vveSTk/pY3StX1ScU3ULnLQaEjP1LVI3pu6R5w7PdQ+Ew6fPmU7RpD8rZPKfFoBcby1mf2Mb/HNk8jXPTHTmyTKBB+othHHg4BWM3Kuw=
name: kwikapi.tornado-0.2.1
tag_name: 0.2.1
name: kwikapi.tornado-0.2.2
tag_name: 0.2.2
on:
repo: deep-compute/kwikapi.tornado
- provider: pypi
Expand Down
32 changes: 27 additions & 5 deletions kwikapi/tornado/kwikapi_tornado.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# -*- coding: utf-8 -*

from tornado.web import RequestHandler as TornadoRequestHandler
from tornado.web import asynchronous
from kwikapi import BaseRequest, BaseResponse, BaseRequestHandler

from deeputil import Dummy

DUMMY_LOG = Dummy()

class TornadoRequest(BaseRequest):

def __init__(self, req_hdlr):
Expand Down Expand Up @@ -33,7 +38,7 @@ def __init__(self, req_hdlr):
self.headers = {}

def write(self, data, proto, stream=False):
super().write(data, proto, stream=stream)
n, t = super().write(data, proto, stream=stream)

for k, v in self.headers.items():
self._req_hdlr.set_header(k, v)
Expand All @@ -42,26 +47,43 @@ def write(self, data, proto, stream=False):

if not stream:
self._req_hdlr.write(d)
return
return n, t

for x in d:
self._req_hdlr.write(x)

return n, t

def flush(self):
self._req_hdlr.flush()

def close(self):
self._req_hdlr.finish()

class RequestHandler(TornadoRequestHandler):
PROTOCOL = BaseRequestHandler.DEFAULT_PROTOCOL

def __init__(self, *args, **kwargs):
api = kwargs.pop('api')
self.api = kwargs.pop('api')
self.log = kwargs.pop('log', DUMMY_LOG)
default_version = kwargs.pop('default_version', None)
self.kwik_req_hdlr = BaseRequestHandler(api, default_version)
default_protocol = kwargs.pop('default_protocol', self.PROTOCOL)
self.kwik_req_hdlr = BaseRequestHandler(self.api,
default_version, default_protocol, log=self.log)

super().__init__(*args, **kwargs)

@asynchronous
def _handle(self):
self.kwik_req_hdlr.handle_request(TornadoRequest(self))
threadpool = self.api.threadpool

def fn():
self.kwik_req_hdlr.handle_request(TornadoRequest(self))
self.finish()

if threadpool:
threadpool.submit(fn)
else:
fn()

get = post = _handle
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

# https://docs.djangoproject.com/en/1.11/intro/reusable-apps/
version = '0.2.1'
version = '0.2.2'
setup(
name="kwikapi-tornado",
version=version,
Expand All @@ -14,7 +14,8 @@
author='Deep Compute, LLC',
author_email='contact@deepcompute.com',
install_requires=[
'tornado==4.5.3',
'tornado==4.5.3',
'deeputil==0.2.5',
],
classifiers=[
'Environment :: Web Environment',
Expand Down

0 comments on commit 65b469e

Please sign in to comment.