This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Motivation: I had to use standard tarfile to create an archive within an async function. | |
# def pack(f): | |
# with tarfile.open(output, "w:gz") as tar: | |
# tar.add(src_dir, arcname="blah") | |
# | |
# async with temp_file() as f: | |
# asyncio.get_running_loop().run_in_executor(None, pack, f) | |
@contextlib.asynccontextmanager | |
async def temp_file() -> Iterator[pathlib.Path]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A snippet to show that pymongo / mongo converts timezone aware datetime objects to UTC, when saving. | |
# docker run --env MONGO_INITDB_DATABASE=brain --env MONGO_INITDB_ROOT_USERNAME=root --env MONGO_INITDB_ROOT_PASSWORD=secret --publish-all mongo:4.2 | |
# | |
# lookup which port it was mapped to: | |
# $ docker container ls | |
# CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
# 8eaf2dd5aedb mongo:4.2 "docker-entrypoint.s…" 6 minutes ago Up 6 minutes 0.0.0.0:55000->27017/tcp brave_moser | |
import datetime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Show threadpool processes only max_workers tasks at the same time and behaves | |
# like a queue | |
import itertools | |
from concurrent import futures | |
from io import StringIO | |
from time import sleep | |
def print_sleep_print(p, out): | |
print("(", file=out, end="") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.4 | |
import cProfile | |
import pstats | |
def first(): | |
pass | |
def second(): |