Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 16 01:04

    njsmith on master

    Replace call to add_stylesheet … Merge pull request #277 from be… (compare)

  • Jun 16 01:04
    njsmith closed #277
  • Jun 15 16:48
    befeleme opened #277
  • Jun 15 14:11
    richardsheridan review_requested #1834
  • Jun 15 14:11
    richardsheridan review_requested #1834
  • Jun 15 14:10
    richardsheridan synchronize #1834
  • Jun 15 13:09
    richardsheridan edited #1834
  • Jun 15 10:22

    pquentin on master

    Bump version to 0.19.0 Bump version to 0.19.0+dev Merge pull request #2040 from p… (compare)

  • Jun 15 10:22
    pquentin closed #2040
  • Jun 15 10:15
    pquentin synchronize #2040
  • Jun 15 09:36

    pquentin on v0.19.0

    Bump version to 0.19.0 (compare)

  • Jun 15 09:26
    pquentin opened #2040
  • Jun 15 09:18
    pquentin edited #1921
  • Jun 15 08:15

    njsmith on master

    Added the "compact" keyword arg… Test against 3.10 alpha Correct matrix variable referen… and 32 more (compare)

  • Jun 15 08:15
    njsmith closed #1921
  • Jun 15 04:22
    richardsheridan synchronize #1834
  • Jun 15 03:52
    richardsheridan synchronize #1834
  • Jun 15 03:50
    richardsheridan ready_for_review #1834
  • Jun 15 03:23
    richardsheridan synchronize #1834
  • Jun 14 19:00
    altendky synchronize #1921
Lura Skye
@Fuyukai
aside from the annoying documentation httpx truly feels like the future of http clients
7 replies
which seems to be part of a disappointing trend where people are abandoning sphinx or rST for worse alternatives e.g. pip switchiing to markdown with a horrible hack to keep using directives or people switching to mkdocs which has nowhere near the nice functionality of sphinx
mfleader
@mfleader
i'm using fastapi 0.65.2 and trio 0.18.0
i used the guest mode
import asyncio
import trio


async def trio_run_with_asyncio(trio_fn, *args):

    asyncio_loop = asyncio.get_running_loop()

    def run_sync_soon_threadsafe(fn):
        asyncio_loop.call_soon_threadsafe(fn)

    done_fut = asyncio.Future()

    def done_callback(trio_main_outcome):
        done_fut.set_result(trio_main_outcome)

    trio.lowlevel.start_guest_run(
        trio_fn, *args,
        run_sync_soon_threadsafe=run_sync_soon_threadsafe,
        done_callback=done_callback,
        host_uses_signal_set_wakeup_fd=True
    )
    trio_main_outcome = await done_fut
    return trio_main_outcome.unwrap()
async def trio_main(tasks):
    results = {}

    async def grabber(s, upstream_job, upstream_job_build, build_tag):
        r = await s.get(
            (f"{airflow_service.base_url}/api/v1"
            f"/dags/{upstream_job}"
            f"/dagRuns/{upstream_job_build}"
            f"/taskInstances/{build_tag}"))
        r.raise_for_status()
        t = r.json()
        results[build_tag] = t['state']

    async with airflow_service.httpx_client() as session:
        async with trio.open_nursery() as n:
            for task in tasks:
                n.start_soon(
                    grabber,
                    session,
                    task['upstream_job'],
                    task['upstream_job_build'],
                    task['build_tag']
                )

    return results
from fastapi import APIRouter
from app.services.search import ElasticService

router = APIRouter()

@router.get('/api/results/{pipeline_id}/{job_id}')
async def results_for_job(pipeline_id: str, job_id: str):
   # query async elasticsearch for tasks
   ...
   tasks_states = await trio_run_with_asyncio(trio_main, tasks)
   for task in tasks:
        task['job_status'] = tasks_states[task['build_tag']]

    return tasks
mfleader
@mfleader
trio issues a run time error when request is made while a request is being processed b/c trio does not want to start a loop within a loop which makes sense
mfleader
@mfleader
i re-implemented it using asyncio.gather to side step that issue for now
Tom Christie
@tomchristie
Any pointers on where to read up on async with aclosing?
I'm not clear from an error message if it's a pattern, a trio thing, or a Python built-in that I'm not aware of.
new in 3.10
Tom Christie
@tomchristie
I'm seeing the warning in 3.8+
Jordan Speicher
@uSpike
Tom Christie
@tomchristie
Right, I think I got it. Thanks!
richardsheridan
@richardsheridan:matrix.org
[m]
an underrated benefit of the trio release is that the stable version of the "awesome trio" page in the docs is current now
graingert
@graingert:matrix.org
[m]
@tomchristie technically you need it for regular generators too
6 replies
Eg on pypy
contextlib.closing or yield from
Mike Nerone
@mikenerone

@graingert:matrix.org

trio-asyncio is compatible with some asyncio setups but not all. anyio is fully compatible with all asyncio setups and trio

This almost sounds like you're saying that anyio can do the job of trio-asyncio. That's not the case, right? If I have a trio app where I have one asyncio library I need to use, I still need trio-asyncio to handle those calls, right?

1 reply
Mike Nerone
@mikenerone

@mfleader Repeating this from earlier thread because some interfaces seem to have trouble notifying people of threads.

how does one change the dependency of a dependency (starlette used by fastapi)?

With Poetry, you can add an optional dep to your app to constrain the version of something pulled in by another dep (of course, the constraints have to have some overlap to be solvable).

Jordan Speicher
@uSpike

unfortunately fastapi is exact in its starlette requirement: https://github.com/tiangolo/fastapi/blob/master/pyproject.toml#L35

requires = ["starlette ==0.14.2",

Dave Hirschfeld
@dhirschfeld
:point_up: that is a bug-bear of mine - tiangolo/fastapi#1555
8 replies
A PR to update the pin might be accepted though
lord_fomo
@goodboy:matrix.org
[m]
wow, seriously loving the new async with (): (with tuple) syntax in 3.9
1 reply
so many indentation levels removed 😂
Alex Grönholm
@agronholm
3.10 wasn't it? or do I misremember
graingert
@graingert:matrix.org
[m]
parenthesises with
lord_fomo
@goodboy:matrix.org
[m]
ohh sorry
yeah basically multiple expressions between parentheses
i guess it was undocumented but in 3.9?
it's so weird i thought i was losing it at first bc they didn't doc it in 3.9 release notes
but it definitely works
@uSpike: so yes that's it
huh i wonder if the match works in 3.9 😂
Seth Michael Larson
@sethmlarson
@mfleader Could you open an issue on elastic/elasticsearch-pyfor HTTPX (+trio) support? Shouldn't be too hard to add. (And if you wanted to try contributing it I'd review as well)
lord_fomo
@goodboy:matrix.org
[m]
someone should bench a trio version:
https://blog.jonlu.ca/posts/async-python-http
Mike Nerone
@mikenerone
In [17]: import time
    ...: import httpx
    ...: import trio
    ...:
    ...: async def get(client, url, index, results):
    ...:     response = await client.get(url)
    ...:     results[index] = response.json()
    ...:
    ...: async def go():
    ...:     results = {}
    ...:     async with httpx.AsyncClient() as client, trio.open_nursery() as nursery:
    ...:         for i in range(40):
    ...:             nursery.start_soon(get, client, f"https://jsonplaceholder.typicode.com/todos/{i}", i, results)
    ...:     #print(results)
    ...:
    ...: start = time.perf_counter()
    ...: await go()
    ...: stop = time.perf_counter()
    ...: print(f"Elapsed time: {stop-start}")
Elapsed time: 0.5561655089999249
@goodboy:matrix.org ^
2015 Macbook, Wifi, blah blah
lord_fomo
@goodboy:matrix.org
[m]
hawt
Pi
@p-i-

This is doing my head in.
I've got a perfectly working web socket streamer using Trio.
It's really simple.
But I modify it slightly and it now fails.

import trio
from trio_websocket import open_websocket_url 

class WSProxy:
    KEEPALIVE_INTERVAL_S = 3

    def __init__(self, url_remote):
        self.url_remote = url_remote

        self.socket_to_remote = None

    async def run(self):
        async with trio.open_nursery() as nursery:
            async def task_socket_to_remote():
                async with open_websocket_url(self.url_remote) as socket_to_remote:
                    print(f'{self.url_remote} connected')
                    self.socket_to_remote = socket_to_remote

                    async def keepalive():
                        while True:
                            print('sending ping')
                            await socket_to_remote.ping()
                            print('Not hit')
                            await trio.sleep(WSProxy.KEEPALIVE_INTERVAL_S)

                    nursery.start_soon(keepalive)
                print('Hits1')

            nursery.start_soon(task_socket_to_remote)
            print('Hits2')
            while True:
                await trio.sleep(1)

ws = WSProxy('wss://ws.hotbit.io')

trio.run(ws.run)

This never reaches the next line after sending the ping.

All I've done is switched the nesting of the nursery and the socket connection.
Pi
@p-i-
Looks like my message is now locked in so I can't edit it.
Here's a stripped down version:
import trio
from trio_websocket import open_websocket_url 

class WSProxy:
    KEEPALIVE_INTERVAL_S = 3
    async def run(self):
        async with open_websocket_url('wss://ws.hotbit.io') as socket_to_remote:
            print('connected')

            async with trio.open_nursery() as nursery:
                async def keepalive():
                    while True:
                        print('sending ping')
                        await socket_to_remote.ping()
                        print('Not hit')
                        await trio.sleep(WSProxy.KEEPALIVE_INTERVAL_S)
                nursery.start_soon(keepalive)
        print('Why not hits???')

ws = WSProxy()
trio.run(ws.run)
The output is just sending ping
Nathaniel J. Smith
@njsmith
...I guess one possibility would be, maybe the peer you're talking to doesn't bother to respond to ping messages?
await my_ws.ping() send a PING frame, and then blocks until it receives a PONG frame from the other side
and in theory websocket servers should always send a PONG frame after getting a PING frame, but, theory and practice are not always the same...