協程的簡單使用

tony_qucheng發表於2020-11-12
import asyncio

loop = asyncio.get_event_loop()

async def insert(report_date, init_asset_entity_list, section):
    pass

if __name__ == "__main__":
    tasks = []
    for section in section_list:
        tasks.append(insert(report_date, init_asset_entity_list, section))
    loop.run_until_complete(asyncio.wait(tasks))


def mysql_section(original_list):
    return_list = []
    max_rows = 50
    original_rows = len(original_list)
    if original_rows > max_rows:
        section_count = int(original_rows / max_rows) + 1
        start = 0
        stop = start + max_rows
        for i in range(section_count):
            temp_list = original_list[start: stop: 1]
            start = stop
            stop = start + max_rows
            return_list.append(temp_list)
    else:
        return_list = [original_list]
    return return_list


相關文章