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

more informative #33

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ async def hello_world(**server):
return 'Hello world!', 'latin-1'

if __name__ == '__main__':
app.run('0.0.0.0', 8000, debug=True)
app.run('0.0.0.0', 8000, debug=True, reload=True)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='tremolo',
version='0.0.301',
version='0.0.302',
license='MIT',
author='nggit',
author_email='[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion tremolo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.0.301'
__version__ = '0.0.302'

from .tremolo import Tremolo # noqa: E402
from . import exceptions # noqa: E402,F401
Expand Down
8 changes: 7 additions & 1 deletion tremolo/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def connection_made(self, transport):
def connection_lost(self, exc):
if self._middlewares['close']:
task = self.loop.create_task(self._connection_lost(exc))
self.loop.call_at(self.loop.time() + 30, task.cancel)
self.loop.call_at(
self.loop.time() + self.options['_app_close_timeout'],
task.cancel)
else:
super().connection_lost(exc)

Expand All @@ -73,6 +75,8 @@ async def _handle_middleware(self, func, options={}):
return options

if not isinstance(data, (bytes, bytearray, str, tuple)):
self.logger.info('middleware %s has exited with the connection '
'possibly left open', func.__name__)
return

if 'status' in options:
Expand Down Expand Up @@ -132,6 +136,8 @@ async def _handle_response(self, func, options={}):
return

if not isinstance(data, (bytes, bytearray, str, tuple)):
self.logger.info('handler %s has exited with the connection '
'possibly left open', func.__name__)
return

status = self.response.get_status()
Expand Down
5 changes: 4 additions & 1 deletion tremolo/lib/http_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def socket(self):
@property
def client(self):
if not self._client:
self._client = self.socket.getpeername()[:2]
try:
self._client = self.socket.getpeername()[:2]
except TypeError:
pass

return self._client

Expand Down
13 changes: 7 additions & 6 deletions tremolo/tremolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self):
(400, handlers.error_400, {}),
(404, handlers.error_404, dict(status=(404, b'Not Found'),
stream=False)),
# must be at the very end
(500, handlers.error_500, {})
],
1: [
Expand All @@ -56,8 +57,8 @@ def __init__(self):
'worker_start': [],
'worker_stop': []
}
self.ports = {}

self._ports = {}
self._loop = None
self._logger = None

Expand All @@ -67,11 +68,11 @@ def listen(self, port, host=None, **options):
host = port
port = None

if (host, port) in self._ports:
if (host, port) in self.ports:
return False

self._ports[(host, port)] = options
return (host, port) in self._ports
self.ports[(host, port)] = options
return (host, port) in self.ports

def route(self, path):
if isinstance(path, int):
Expand Down Expand Up @@ -605,7 +606,7 @@ def run(self, host=None, port=0, reuse_port=True, worker_num=1, **kwargs):
print()

if host is None:
if not self._ports:
if not self.ports:
raise ValueError(
'with host=None, listen() must be called first'
)
Expand All @@ -627,7 +628,7 @@ def run(self, host=None, port=0, reuse_port=True, worker_num=1, **kwargs):

print('Options:')

for (_host, _port), options in self._ports.items():
for (_host, _port), options in self.ports.items():
if _host is None:
_host = host

Expand Down