Minor: rename background task fluff
このコミットが含まれているのは:
コミット
47f0b529bf
|
@ -60,16 +60,18 @@ def create_app(toml_config):
|
||||||
app.stream_viewership = None
|
app.stream_viewership = None
|
||||||
app.last_info_task = None
|
app.last_info_task = None
|
||||||
|
|
||||||
# Background tasks' asyncio.sleep tasks, cancelled on shutdown
|
# asyncio tasks to be cancelled on shutdown
|
||||||
app.background_sleep = set()
|
app.tasks = set()
|
||||||
|
|
||||||
# Queues for event socket clients
|
# Queues for event socket clients
|
||||||
app.event_queues = set()
|
app.event_queues = set()
|
||||||
|
|
||||||
@app.after_serving
|
@app.after_serving
|
||||||
async def shutdown():
|
async def shutdown():
|
||||||
# Force all background tasks to finish
|
# Cancel started asyncio tasks that would otherwise block shutdown
|
||||||
for task in app.background_sleep:
|
# The asyncio tasks we create are:
|
||||||
|
# * quart background tasks awaiting asyncio.sleep()
|
||||||
|
for task in app.tasks:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
|
|
||||||
@app.before_serving
|
@app.before_serving
|
||||||
|
|
|
@ -6,8 +6,8 @@ import json
|
||||||
|
|
||||||
from quart import current_app
|
from quart import current_app
|
||||||
|
|
||||||
async def start_event_server_at(address):
|
def start_event_server_at(address):
|
||||||
return await asyncio.start_unix_server(serve_event_client, address)
|
return asyncio.start_unix_server(serve_event_client, address)
|
||||||
|
|
||||||
async def serve_event_client(reader, writer):
|
async def serve_event_client(reader, writer):
|
||||||
reader.feed_eof()
|
reader.feed_eof()
|
||||||
|
|
|
@ -19,14 +19,13 @@ USERS = current_app.users
|
||||||
CAPTCHAS = current_app.captchas
|
CAPTCHAS = current_app.captchas
|
||||||
CAPTCHA_SIGNER = current_app.captcha_signer
|
CAPTCHA_SIGNER = current_app.captcha_signer
|
||||||
|
|
||||||
async def sleep_and_collect_task(delay):
|
async def cancel_on_shutdown(coro):
|
||||||
coro = asyncio.sleep(delay)
|
|
||||||
task = asyncio.create_task(coro)
|
task = asyncio.create_task(coro)
|
||||||
current_app.background_sleep.add(task)
|
current_app.tasks.add(task)
|
||||||
try:
|
try:
|
||||||
await task
|
await task
|
||||||
finally:
|
finally:
|
||||||
current_app.background_sleep.remove(task)
|
current_app.tasks.remove(task)
|
||||||
|
|
||||||
def with_period(period):
|
def with_period(period):
|
||||||
def periodically(f):
|
def periodically(f):
|
||||||
|
@ -35,7 +34,7 @@ def with_period(period):
|
||||||
for iteration in itertools.count():
|
for iteration in itertools.count():
|
||||||
await f(iteration, *args, **kwargs)
|
await f(iteration, *args, **kwargs)
|
||||||
try:
|
try:
|
||||||
await sleep_and_collect_task(period)
|
await cancel_on_shutdown(asyncio.sleep(period))
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
読み込み中…
新しいイシューから参照