python-trio

Python - How to cancel a specific task spawned by a nursery in python-trio

痞子三分冷 提交于 2020-04-07 05:26:19
问题 I have an async function that listens on a specific port. I want to run the function on a few ports at a time and when the user wants to stop listening on a specific port, stop the function listening on that port. Previously I was using the asyncio library for this task and I tackled this problem by creating tasks with a unique id as their name. asyncio.create_task(Func(), name=UNIQUE_ID) Since trio uses nurseries to spawn tasks, I can see the running tasks by using nursery.child_tasks but

Spawn processes and communicate between processes in a trio based Python application

可紊 提交于 2020-01-03 03:36:07
问题 For an internship on the Python library fluidimage, we are investigating if it could be a good idea to write a HPC parallel application with a client/servers model using the library trio. For asynchronous programming and i/o, trio is indeed great! Then, I'm wondering how to spawn processes (the servers doing the CPU-GPU bounded work) communicating complex Python objects (potentially containing large numpy arrays) between the processes. I didn't find what was the recommended way to do this

Combining semaphore and time limiting in python-trio with asks http request

烂漫一生 提交于 2019-12-11 15:44:02
问题 I'm trying to use Python in an async manner in order to speed up my requests to a server. The server has a slow response time (often several seconds, but also sometimes faster than a second), but works well in parallel . I have no access to this server and can't change anything about it. So, I have a big list of URLs (in the code below, pages ) which I know beforehand, and want to speed up their loading by making NO_TASKS=5 requests at a time. On the other hand, I don't want to overload the

How can I read one line at a time from a trio ReceiveStream?

自闭症网瘾萝莉.ら 提交于 2019-12-10 13:19:51
问题 asyncio has StreamReader.readline(), allowing something like: while True: line = await reader.readline() ... (I don't see async for available in asyncio but that would be the obvious evolution) How do I achieve the equivalent with trio? I don't see any high level support for this directly in trio 0.9. All I see is ReceiveStream.receive_some() which returns arbitrary sized binary chunks; it seems non-trivial to me to decode and convert this to something line-wise. Is there a standard library

How can I read one line at a time from a trio ReceiveStream?

早过忘川 提交于 2019-12-08 22:17:41
问题 asyncio has StreamReader.readline(), allowing something like: while True: line = await reader.readline() ... (I don't see async for available in asyncio but that would be the obvious evolution) How do I achieve the equivalent with trio? I don't see any high level support for this directly in trio 0.9. All I see is ReceiveStream.receive_some() which returns arbitrary sized binary chunks; it seems non-trivial to me to decode and convert this to something line-wise. Is there a standard library

What is the core difference between asyncio and trio?

允我心安 提交于 2019-12-03 01:53:19
问题 Today, I found a library named trio which says itself is an asynchronous API for humans. These words are a little similar with requests '. As requests is really a good library, I am wondering what is the advantages of trio . There aren't many articles about it, I just find an article discussing curio and asyncio . To my surprise, trio says itself is even better than curio (next-generation curio). After reading half of the article, I cannot find the core difference between these two

What is the core difference between asyncio and trio?

萝らか妹 提交于 2019-12-02 15:29:11
Today, I found a library named trio which says itself is an asynchronous API for humans. These words are a little similar with requests '. As requests is really a good library, I am wondering what is the advantages of trio . There aren't many articles about it, I just find an article discussing curio and asyncio . To my surprise, trio says itself is even better than curio (next-generation curio). After reading half of the article, I cannot find the core difference between these two asynchronous framework. It just gives some examples that curio 's implementation is more convenient than asyncio