Skip to content

Instantly share code, notes, and snippets.

View liweicheng00's full-sized avatar

Leonard liweicheng00

  • Taiwan
View GitHub Profile
@liweicheng00
liweicheng00 / update_nest_dict.py
Created July 14, 2022 03:24
Update nest dictionary fro Python
def update(d: dict, u) -> dict:
for k, v in u.items():
if isinstance(v, collections.abc.Mapping):
d[k] = update(d.get(k, {}), v)
else:
d[k] = v
return d
@liweicheng00
liweicheng00 / asyncio_test.py
Last active July 14, 2022 06:26
asyncio for block function
import asyncio
import time
import random
def random_sleep(task_id: int):
for t in range(5):
sleep = random.randrange(1000, 2000, 1)
time.sleep(sleep / 1000)
print(f'task_id: {task_id}, running ({t})')