Skip to content

Instantly share code, notes, and snippets.

View turtiesio's full-sized avatar
😃

David Hwang turtiesio

😃
View GitHub Profile
@turtiesio
turtiesio / python_tail_.py
Created November 9, 2022 08:46
using tail -F, keep track of log file even log rotation happens
import subprocess
def tail(filename: str) -> Generator[str, None, None]:
proc = subprocess.Popen(["tail", "-F", filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
line = proc.stdout.readline()
if line:
yield line.decode("utf-8")
else:
break
@turtiesio
turtiesio / python_asyncio_graceful_shutdown.py
Last active October 31, 2022 01:49
python asyncio graceful shutdown with SIGINT, SIGTERM
import signal
import asyncio
import logging
def register_graceful_shutdown(loop: asyncio.AbstractEventLoop):
""" Register signal handlers """
for s in (signal.SIGINT, signal.SIGTERM):
loop.add_signal_handler(s, _signal_exit, s, loop) # pass s(signal), loop to _signal_exit
import ssl
import asyncio
import logging
import weakref
from typing import Tuple
class SNIStore(ssl.SSLContext):
""" SSLContextContainer to store the SNI value """