Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 21:28

    njsmith on master

    get_comment_body now always ret… Merge pull request #85 from njs… (compare)

  • 21:28
    njsmith closed #85
  • 21:23
    njsmith opened #85
  • 19:02

    njsmith on master

    Try using github actions for CI Merge pull request #84 from njs… (compare)

  • 19:02
    njsmith closed #84
  • 18:50
    njsmith synchronize #84
  • 18:47
    njsmith synchronize #84
  • 18:47
    pquentin closed #1388
  • 18:43
    njsmith opened #84
  • 18:23
    njsmith reopened #1396
  • 18:23
    njsmith closed #1396
  • 18:19

    njsmith on master

    Add note about cancellation and… Merge pull request #1365 from d… (compare)

  • 18:19
    njsmith closed #1365
  • 18:18

    njsmith on master

    add a deprecation warning for p… remove an unneeded import state… apply yapf formatting and 1 more (compare)

  • 18:18
    njsmith closed #1408
  • 16:34
    wgwz synchronize #1408
  • 16:28
    wgwz synchronize #1396
  • 16:18
    wgwz opened #1408
  • 15:51
    wgwz synchronize #1396
  • 11:04

    dependabot-preview[bot] on pip

    (compare)

Joshua Oreman
@oremanj

then "on cancellation, cancel B, wait for B to exit, cancel C" is

async with open_service_nursery() as nursery:
    nursery.start_soon(task_C)
    await task_B()

and if you really do want the one-second sleep, you could do

    try:
        await task_B()
    except trio.Cancelled:
        with trio.CancelScope(shield=True):
            await trio.sleep(1)
        raise
Nathaniel J. Smith
@njsmith
I thought we had an issue that discusses the service nurseries and stuff too, but now I can't find it
Maybe it's mixed in with the multierror v2 thread or something?
Nathaniel J. Smith
@njsmith
@tjstum_gitlab in the past @smurfix has been the main trio-asyncio maintainer, but he got busy with real life stuff, so it hasn't been getting a lot of attention. Any chance you want to be the new maintainer? :-)
NoskLo
@nosklo_gitlab
I want to assert that some async iterator is exhausted; how can I pytest it?
I found it, pytest.raises(StopAsyncIteration)
Tim Stumbaugh
@tjstum_gitlab
@njsmith Possibly. I will have to do some soul searching to think about if I can really take it on. I would also want to do more to understand its internals and style, so I don't just become a bad steward. I'll give it some more thought!
Nathaniel J. Smith
@njsmith
@tjstum_gitlab no worries! you're also welcome to volunteer on a more limited basis, if that works better for you, or you want to get a taste for it before deciding. Or do nothing at all :-)
Alex Boag-Munroe
@Ninpo
When creating tests for trio apps, how is one supposed to test individual coroutine calls? In a normal app I tend to go into trio.run pretty early, but for testing I'd want to test in as small chunks as possible
nursery jobs can't return things either so this is unchartered waters for me
Quentin Pradet
@pquentin
are you using pytest-trio?
Alex Boag-Munroe
@Ninpo
I can be, I've gone with pytest
ah ha, and there's docs, thanks @pquentin
Quentin Pradet
@pquentin
:+1:
Nathaniel J. Smith
@njsmith
A long post grappling with the names of Stream and Channel: python-trio/trio#1208
Matthias Urlichs
@smurfix
@njsmith The list misses two backticks.
Nathaniel J. Smith
@njsmith
@smurfix fixed, thanks
Dave Hirschfeld
@dhirschfeld
Maybe Channel[T] is fine and Stream just needs to be renamed to ByteStream to prevent any confusion. It breaks the naming symmetry you have in the post but that does highlight that they're different things so ¯\(ツ)/¯?
dhirschfeld @dhirschfeld returns to lurking...
Peter Sutton
@dj-foxxy

I'm using trio.Path.read_text(), code worked until I started using a nursery. Now I get,

  File "/usr/lib/python3.7/site-packages/trio/_core/_traps.py", line 43, in cancel_shielded_checkpoint
    return (await _async_yield(CancelShieldedCheckpoint)).unwrap()
AttributeError: 'NoneType' object has no attribute 'unwrap'

Does this look like a common error? Do I need to post more code?

oakkitten
@oakkitten
if there's a Stream[bytes] and ByteStream, that's even more confusing
oakkitten
@oakkitten
one day someone will want to subclass Stream[bytes] that makes bytes uppercase and they will name it UppercasingByteStream
Laura F. D.
@Fuyukai
I mean the stdlib isn't any better
List[bytes] and bytearray comes to mind
Peter Sutton
@dj-foxxy
the process async context manager tries to kill on cancellation. This fails 'Operation not permitted' if the subprocess is sudo. How can I customize the behaviour?
Tim Stumbaugh
@tjstum_gitlab
Huh, I always thought that sudo relays signals to its child
Peter Sutton
@dj-foxxy
@tjstum_gitlab I'm not sure of the details but this example highlights the issue:
import trio

async def main():
    with trio.move_on_after(1):
        await trio.run_process(['sleep', '2'])
    print('Cancelled 1')

    with trio.move_on_after(1):
        await trio.run_process(['sudo', 'sleep', '2'])
    print('Cancelled 2')

trio.run(main)
Alex Boag-Munroe
@Ninpo
Isn't there a switch that helps that so subprocesses can be killed by the adult
preexec_fn=os.setpgrp I needed this so that my child processes could be killed by parent
Peter Sutton
@dj-foxxy
@Ninpo just passing preexec_fn=os.setpgrp doesn't seem to solve the problem.
Alex Boag-Munroe
@Ninpo
After the list not part of it right
trio.run_process(['sudo', 'sleep', '2'], preexec_fn=os.setpgrp)
Peter Sutton
@dj-foxxy
@Ninpo this is what I've got:
import os

import trio


async def main():
    with trio.move_on_after(1):
        await trio.run_process(['sleep', '2'])
    print('Cancelled 1')

    with trio.move_on_after(1):
        await trio.run_process(['sudo', 'sleep', '2'], preexec_fn=os.setpgrp)
    print('Cancelled 2')

trio.run(main)
Alex Boag-Munroe
@Ninpo
hrm. That's definitely usually the way to solve this problem :/
Peter Sutton
@dj-foxxy
@Ninpo, yep I use that solution with plain subprocess but it doesn't seem to be working here for me.
Alex Boag-Munroe
@Ninpo
Might be worth seeing how move_on_after is trying to kill it
Peter Sutton
@dj-foxxy
Also, is there a way of limited the max number of subprocesses?
NoskLo
@nosklo_gitlab
Just use a CapacityLimiter
limit = trio.CapacityLimiter(5)
... then later ...
async with limit:
    await trio.run_process(....)
Peter Sutton
@dj-foxxy
@nosklo_gitlab Exactly what I need!
Alex Boag-Munroe
@Ninpo
Is that new? I normally use Semaphore
NoskLo
@nosklo_gitlab
@Ninpo it is like a Semaphore but more specific to this use case; Also it has some additional error checking built-in
Alex Boag-Munroe
@Ninpo
Just finished reading the docs on it, nice
and probably what I'll use where I'd used Semaphore before :)
saves me passing it around so I can acquire and release in the right place
Tim Stumbaugh
@tjstum_gitlab

Calling socket.is_readable() on a closed socket raises a ValueError:

trio/_socket.py in is_readable(self)
    485             return bool(rready)
    486         p = select.poll()
--> 487         p.register(self._sock, select.POLLIN)
    488         return bool(p.poll(0))
    489

ValueError: file descriptor cannot be a negative integer (-1)

i can put together a patch to change that to a trio.ClosedResourceError if that's the desired approach there

Peter Sutton
@dj-foxxy
I've just "finished" my first project using trio: a simple MAC scanner. If anyone has got a seconds, I'd like some feedback (am I using trio correctly). https://git.fds.im/snippets/4