Merge branch 'master' into streaming

This commit is contained in:
L. Kärkkäinen
2020-03-02 14:05:15 +02:00
8 changed files with 56 additions and 34 deletions

View File

@@ -1177,6 +1177,12 @@ class Sanic:
try:
self.is_running = True
if workers > 1 and os.name != "posix":
logger.warn(
f"Multiprocessing is currently not supported on {os.name},"
" using workers=1 instead"
)
workers = 1
if workers == 1:
if auto_reload and os.name != "posix":
# This condition must be removed after implementing

View File

@@ -1,11 +1,11 @@
import asyncio
import multiprocessing
import os
import sys
from asyncio import CancelledError
from functools import partial
from inspect import isawaitable
from multiprocessing import Process
from signal import SIG_IGN, SIGINT, SIGTERM, Signals
from signal import signal as signal_func
from socket import SO_REUSEADDR, SOL_SOCKET, socket
@@ -613,9 +613,10 @@ def serve_multiple(server_settings, workers):
signal_func(SIGINT, lambda s, f: sig_handler(s, f))
signal_func(SIGTERM, lambda s, f: sig_handler(s, f))
mp = multiprocessing.get_context("fork")
for _ in range(workers):
process = Process(target=serve, kwargs=server_settings)
process = mp.Process(target=serve, kwargs=server_settings)
process.daemon = True
process.start()
processes.append(process)

View File

@@ -23,7 +23,7 @@ class SanicTestClient:
self.host = host
def get_new_session(self):
return httpx.Client()
return httpx.AsyncClient(verify=False)
async def _local_request(self, method, url, *args, **kwargs):
logger.info(url)
@@ -38,7 +38,7 @@ class SanicTestClient:
try:
response = await getattr(session, method.lower())(
url, verify=False, *args, **kwargs
url, *args, **kwargs
)
except httpx.exceptions.ConnectionClosed:
logger.error(
@@ -48,15 +48,17 @@ class SanicTestClient:
except NameError:
raise Exception(response.status_code)
response.body = await response.aread()
response.status = response.status_code
response.content_type = response.headers.get("content-type")
# response can be decoded as json after response._content
# is set by response.aread()
try:
response.json = response.json()
except (JSONDecodeError, UnicodeDecodeError):
response.json = None
response.body = await response.read()
response.status = response.status_code
response.content_type = response.headers.get("content-type")
if raw_cookies:
response.raw_cookies = {}
@@ -189,11 +191,11 @@ async def app_call_with_return(self, scope, receive, send):
return await asgi_app()
class SanicASGIDispatch(httpx.dispatch.ASGIDispatch):
class SanicASGIDispatch(httpx.dispatch.asgi.ASGIDispatch):
pass
class SanicASGITestClient(httpx.Client):
class SanicASGITestClient(httpx.AsyncClient):
def __init__(
self,
app,