Skip to content

Instantly share code, notes, and snippets.

View ateska's full-sized avatar

Ales Teska ateska

View GitHub Profile
@ateska
ateska / asyncio-subprocess.py
Last active October 14, 2022 07:57
Simultaneously read stdout and stderr from Python `asyncio` create_subprocess_exec
import asyncio
async def run():
proc = await asyncio.create_subprocess_exec(
'/bin/ls', '/etc', '/not-exists',
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
# Prepare set of asynchronous readline() tasks for `stdout` and `stderr` streams
import os
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
# Initialize a Web API client with your bot token
slack_bot_token = 'xoxb-your-bot-token'
client = WebClient(token=slack_bot_token)
# Define the message text
message_text = 'Hello, this is a message with a PDF attachment'
@ateska
ateska / streaming_tar.py
Last active January 1, 2026 11:05
Streaming asynchronous non-blocking tar using Python and asyncio
import os.path
import aiohttp.web
async def get_tar(request):
'''
AIOHTTP server handler for GET request that wants to download files from a `directory` using TAR.
'''
directory = <specify the directory>
response = aiohttp.web.StreamResponse(
@ateska
ateska / getaddrinfo_demo.py
Last active June 21, 2025 05:56
Demonstration of Python asyncio.getaddrinfo()
#!/usr/bin/env python3
import asyncio
import socket
import sys
_AI_ADDRCONFIG = socket.AI_ADDRCONFIG
if hasattr(socket, "AI_MASK"):
_AI_ADDRCONFIG &= socket.AI_MASK