Last active
November 25, 2023 21:16
-
-
Save anoduck/7f14620868a2ca47b50263d87302d859 to your computer and use it in GitHub Desktop.
Script repeating `trio.ClosedResourceError`
This file contains hidden or 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
import trio | |
from aioresult import ResultCapture | |
import string | |
async def task(receiver): | |
new_list = [] | |
list_nums = [] | |
alpha_nums = [] | |
async with receiver: | |
async for x in receiver: | |
if str(x).isdigit(): | |
list_nums.append(x) | |
if str(x).isalpha(): | |
alpha_nums.append(x) | |
for letter in alpha_nums: | |
for number in list_nums: | |
value = str(letter).join(number) | |
new_list.append(value) | |
await trio.sleep(0.1) | |
return new_list | |
async def mailer(i, sender): | |
async with sender: | |
await sender.send(i) | |
async def send_it(sender): | |
letters = string.ascii_letters | |
numbers = string.digits | |
abc_list = [[x for x in letters].extend([y for y in numbers])] | |
async with trio.open_nursery() as send_nurse: | |
[send_nurse.start_soon(mailer, i, sender.clone()) for i in abc_list] | |
async def main(): | |
sender, receiver = trio.open_memory_channel(1) | |
async with trio.open_nursery() as nursery: | |
async with sender, receiver: | |
nursery.start_soon(send_it, sender) | |
return1 = ResultCapture.start_soon(nursery, task, receiver.clone()) | |
result1 = return1.result() | |
print('{0} return type = {1}'.format(result1, type(result1))) | |
if __name__ == "__main__": | |
trio.run(main) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running the script with 39 and 40 swapped, resulted in the execution of the script hanging.