Skip to content
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 .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- 'cp311-*'
- 'cp312-*'
- 'cp313-*'
- 'pp310-*'
- 'pp311-*'
cibw_arch: ['x86_64']
timeout-minutes: 10
steps:
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/tests_and_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
python_version:
- '3.13'
- '3.12'
- '3.11'
- '3.10'
- '3.9'
- '3.8'
- '3.7'
- 'pypy3.10'
os: ['ubuntu-20.04', 'windows-latest']
- 'pypy3.11'
os: ['ubuntu-22.04', 'windows-latest']
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
Expand All @@ -48,7 +48,6 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade coverage
python -m pip install --upgrade awaiter
python -m pip install --upgrade tremolo
if: ${{ contains(env.FILES_MODIFIED, '.py') }}

Expand All @@ -60,7 +59,7 @@ jobs:
python -m flake8 httpout/
if: |
contains(env.FILES_MODIFIED, '.py') &&
matrix.os == 'ubuntu-20.04' && matrix.python_version == '3.13'
matrix.os == 'ubuntu-22.04' && matrix.python_version == '3.13'

- name: Run tests
run: python -m tests
Expand Down Expand Up @@ -110,7 +109,6 @@ jobs:
echo "$HOME/.local/bin" >> $GITHUB_PATH
python -m pip install --upgrade pip
python -m pip install --upgrade coverage
python -m pip install --upgrade awaiter
python -m pip install --upgrade tremolo
if: ${{ contains(env.FILES_MODIFIED, '.py') }}

Expand Down
23 changes: 7 additions & 16 deletions httpout/httpout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from types import ModuleType

from awaiter import MultiThreadExecutor
from tremolo.exceptions import BadRequest, NotFound, Forbidden
from tremolo.lib.websocket import WebSocket
from tremolo.utils import html_escape
Expand All @@ -22,15 +21,13 @@
class HTTPOut:
def __init__(self, app):
app.add_hook(self._on_worker_start, 'worker_start')
app.add_hook(self._on_worker_stop, 'worker_stop')
app.add_hook(self._on_close, 'close')
app.add_middleware(self._on_request, 'request', priority=9999) # low
app.add_middleware(self._on_close, 'close')

async def _on_worker_start(self, **worker):
loop = worker['loop']
logger = worker['logger']
g = worker['globals']
thread_pool_size = g.options.get('thread_pool_size', 5)
document_root = os.path.abspath(
g.options.get('document_root', os.getcwd())
)
Expand Down Expand Up @@ -152,17 +149,10 @@ def ho_import(name, globals=None, locals=None, fromlist=(), level=0):

g.wait = wait
g.caches = {}
g.executor = MultiThreadExecutor(thread_pool_size)
g.executor.start()

if module:
exec_module(module)

async def _on_worker_stop(self, **worker):
g = worker['globals']

await g.executor.shutdown()

async def _on_request(self, **server):
request = server['request']
response = server['response']
Expand Down Expand Up @@ -258,7 +248,8 @@ async def _on_request(self, **server):

try:
# execute module in another thread
result = await g.executor.submit(exec_module, module, code)
result = await g.executor.submit(exec_module,
args=(module, code))
await server['response'].join()

if result:
Expand All @@ -273,7 +264,8 @@ async def _on_request(self, **server):
await server['response'].handle_exception(exc)
finally:
await g.executor.submit(
cleanup_modules, server['modules'], g.options['debug']
cleanup_modules,
args=(server['modules'], g.options['debug'])
)
await server['response'].join()
server['modules'].clear()
Expand All @@ -285,9 +277,8 @@ async def _on_request(self, **server):
raise Forbidden(f'Disallowed file extension: {ext}')

logger.info('%s -> %s: %s', path, mime_types[ext], module_path)
await response.sendfile(
module_path, content_type=mime_types[ext], executor=g.executor
)
await response.sendfile(module_path, content_type=mime_types[ext])

# exit middleware without closing the connection
return True

Expand Down
4 changes: 2 additions & 2 deletions httpout/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
class HTTPResponse:
def __init__(self, response):
self.response = response
self.loop = response.request.protocol.loop
self.logger = response.request.protocol.logger
self.loop = response.request.server.loop
self.logger = response.request.server.logger
self.tasks = set()

def __getattr__(self, name):
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ description = """\
"""
requires-python = '>=3.7'
dependencies = [
'awaiter',
'tremolo>=0.2.0',
]
license = { text = 'MIT License' }
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
awaiter
tremolo>=0.2.0
tremolo>=0.4.0