Skip to content

Instantly share code, notes, and snippets.

@devlights
devlights / asyncio_evloop_thread.py
Last active February 17, 2023 08:14
[python][asyncio] イベントループを別スレッドで動作させてメインスレッドは生かすサンプル
# ------------------------------------------------
# イベントループを別スレッドで動作させて
# メインスレッドは生かすサンプル
#
# asyncio をつかった処理にて、別スレッドから
# イベントスレッドに対して処理を行う場合
# イベントスレッド自体がスレッドセーフではないため
# 専用のメソッドを利用する必要がある
#
# - ev_loop.call_soon_threadsafe()
@dmfigol
dmfigol / asyncio_loop_in_thread.py
Last active September 5, 2024 18:28
Python asyncio event loop in a separate thread
"""
This gist shows how to run asyncio loop in a separate thread.
It could be useful if you want to mix sync and async code together.
Python 3.7+
"""
import asyncio
from datetime import datetime
from threading import Thread
from typing import Tuple, List, Iterable
@ultrafunkamsterdam
ultrafunkamsterdam / Python 3.6 Asyncio multiple async event loops in multiple threads. Running and shutting down gracefully.py
Last active December 16, 2023 01:33
Python 3.6 Asyncio multiple async event loops in multiple threads. Running and shutting down gracefully
import asyncio
import threading
import random
import time
async def coro(n, name):
for i in range(n):
sleep_time = random.uniform(.3, .7)
print('coro({0}) [{1}/{2}] -> sleep_time {3:.2f}'.format(name, i, n, sleep_time), flush=True)
await asyncio.sleep(sleep_time)
@jae-jae
jae-jae / install-aria2-ui.sh
Last active August 22, 2024 09:33
Ubuntu安装并配置aria2
#!/bin/bash
#
# Ubuntu安装并配置aria2
#
# @Author: Jaeger <JaegerCode@gmail.com>
# @Version: 0.1
#配置文件下载保存路径
downloadPath='/user-files/superuser/dl'
@dmyersturnbull
dmyersturnbull / groupyby_parallel.py
Last active February 6, 2024 00:43
Performs a Pandas groupby operation in parallel
import pandas as pd
import itertools
import time
import multiprocessing
from typing import Callable, Tuple, Union
def groupby_parallel(
groupby_df: pd.core.groupby.DataFrameGroupBy,
func: Callable[[Tuple[str, pd.DataFrame]], Union[pd.DataFrame, pd.Series]],
num_cpus: int = multiprocessing.cpu_count() - 1,
@stackia
stackia / homebrew.mxcl.aria2.plist
Last active October 13, 2023 04:50
aria2c daemon start at boot. Put this file into /Library/LaunchDaemons, them 'chmod 600' and 'chown root'. Remember to fill placeholders below.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.aria2</string>
@h0tw1r3
h0tw1r3 / aria2.daemon
Last active September 1, 2024 17:44
Aria2c systemd service
continue
dir=/var/www/downloads
file-allocation=falloc
max-connection-per-server=4
max-concurrent-downloads=2
max-overall-download-limit=0
min-split-size=25M
rpc-allow-origin-all=true
rpc-secret=YouShouldChangeThis
input-file=/var/tmp/aria2c.session