Skip to content

Commit bdb4697

Browse files
authored
release 0.0.302 (#33)
* more informative * clean up --------- Co-authored-by: nggit <[email protected]>
1 parent 2f16c98 commit bdb4697

File tree

6 files changed

+21
-11
lines changed

6 files changed

+21
-11
lines changed

hello.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ async def hello_world(**server):
1010
return 'Hello world!', 'latin-1'
1111

1212
if __name__ == '__main__':
13-
app.run('0.0.0.0', 8000, debug=True)
13+
app.run('0.0.0.0', 8000, debug=True, reload=True)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='tremolo',
10-
version='0.0.301',
10+
version='0.0.302',
1111
license='MIT',
1212
author='nggit',
1313
author_email='[email protected]',

tremolo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.0.301'
1+
__version__ = '0.0.302'
22

33
from .tremolo import Tremolo # noqa: E402
44
from . import exceptions # noqa: E402,F401

tremolo/http_server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def connection_made(self, transport):
5656
def connection_lost(self, exc):
5757
if self._middlewares['close']:
5858
task = self.loop.create_task(self._connection_lost(exc))
59-
self.loop.call_at(self.loop.time() + 30, task.cancel)
59+
self.loop.call_at(
60+
self.loop.time() + self.options['_app_close_timeout'],
61+
task.cancel)
6062
else:
6163
super().connection_lost(exc)
6264

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

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

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

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

137143
status = self.response.get_status()

tremolo/lib/http_request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ def socket(self):
8686
@property
8787
def client(self):
8888
if not self._client:
89-
self._client = self.socket.getpeername()[:2]
89+
try:
90+
self._client = self.socket.getpeername()[:2]
91+
except TypeError:
92+
pass
9093

9194
return self._client
9295

tremolo/tremolo.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self):
3636
(400, handlers.error_400, {}),
3737
(404, handlers.error_404, dict(status=(404, b'Not Found'),
3838
stream=False)),
39+
# must be at the very end
3940
(500, handlers.error_500, {})
4041
],
4142
1: [
@@ -56,8 +57,8 @@ def __init__(self):
5657
'worker_start': [],
5758
'worker_stop': []
5859
}
60+
self.ports = {}
5961

60-
self._ports = {}
6162
self._loop = None
6263
self._logger = None
6364

@@ -67,11 +68,11 @@ def listen(self, port, host=None, **options):
6768
host = port
6869
port = None
6970

70-
if (host, port) in self._ports:
71+
if (host, port) in self.ports:
7172
return False
7273

73-
self._ports[(host, port)] = options
74-
return (host, port) in self._ports
74+
self.ports[(host, port)] = options
75+
return (host, port) in self.ports
7576

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

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

628629
print('Options:')
629630

630-
for (_host, _port), options in self._ports.items():
631+
for (_host, _port), options in self.ports.items():
631632
if _host is None:
632633
_host = host
633634

0 commit comments

Comments
 (0)