Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On trio backend, CapacityLimiter does not take keyword arguments #515

Closed
burnpanck opened this issue Dec 30, 2022 · 1 comment · Fixed by #666
Closed

On trio backend, CapacityLimiter does not take keyword arguments #515

burnpanck opened this issue Dec 30, 2022 · 1 comment · Fixed by #666

Comments

@burnpanck
Copy link

MWE:

import anyio

async def test():
    lim = anyio.CapacityLimiter(total_tokens=1)
    async with lim:
        await anyio.sleep(0.5)
        
with anyio.start_blocking_portal(backend="trio") as portal:
    portal.start_task_soon(test).result()

fails with TypeError: CapacityLimiter.__init__() got an unexpected keyword argument 'total_tokens'.

This doesn't happen when supplying the tokens as positional arguments or when using the asyncio backend.

@ljluestc
Copy link


import anyio

async def test():
    # Initialize CapacityLimiter with a positional argument
    lim = anyio.CapacityLimiter(1)
    async with lim:
        await anyio.sleep(0.5)

with anyio.start_blocking_portal(backend="trio") as portal:
    portal.start_task_soon(test).result()

mkjpryor pushed a commit to stackhpc/cluster-api-addon-provider that referenced this issue Feb 19, 2024
Bumps [anyio](https://github.com/agronholm/anyio) from 4.2.0 to 4.3.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/agronholm/anyio/releases">anyio's
releases</a>.</em></p>
<blockquote>
<h2>4.3.0</h2>
<ul>
<li>
<p>Added support for the Python 3.12 <code>walk_up</code> keyword
argument in <code>anyio.Path.relative_to()</code> (PR by Colin
Taylor)</p>
</li>
<li>
<p>Fixed passing <code>total_tokens</code> to
<code>anyio.CapacityLimiter()</code> as a keyword argument not working
on the <code>trio</code> backend (<a
href="https://redirect.github.com/agronholm/anyio/issues/515">#515</a>)</p>
</li>
<li>
<p>Fixed <code>Process.aclose()</code> not performing the minimum level
of necessary cleanup when cancelled. Previously:</p>
<ul>
<li>Cancellation of <code>Process.aclose()</code> could leak an orphan
process</li>
<li>Cancellation of <code>run_process()</code> could very briefly leak
an orphan process.</li>
<li>Cancellation of <code>Process.aclose()</code> or
<code>run_process()</code> on Trio could leave standard streams
unclosed</li>
</ul>
<p>(PR by Ganden Schaffner)</p>
</li>
<li>
<p>Fixed <code>Process.stdin.aclose()</code>,
<code>Process.stdout.aclose()</code>, and
<code>Process.stderr.aclose()</code> not including a checkpoint on
asyncio (PR by Ganden Schaffner)</p>
</li>
<li>
<p>Fixed documentation on how to provide your own typed attributes</p>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/agronholm/anyio/blob/master/docs/versionhistory.rst">anyio's
changelog</a>.</em></p>
<blockquote>
<h1>Version history</h1>
<p>This library adheres to <code>Semantic Versioning 2.0
&lt;http://semver.org/&gt;</code>_.</p>
<p><strong>4.3.0</strong></p>
<ul>
<li>
<p>Added support for the Python 3.12 <code>walk_up</code> keyword
argument in
<code>anyio.Path.relative_to()</code> (PR by Colin Taylor)</p>
</li>
<li>
<p>Fixed passing <code>total_tokens</code> to
<code>anyio.CapacityLimiter()</code> as a keyword argument
not working on the <code>trio</code> backend
(<code>[#515](agronholm/anyio#515)
&lt;https://github.com/agronholm/anyio/issues/515&gt;</code>_)</p>
</li>
<li>
<p>Fixed <code>Process.aclose()</code> not performing the minimum level
of necessary cleanup when
cancelled. Previously:</p>
<ul>
<li>Cancellation of <code>Process.aclose()</code> could leak an orphan
process</li>
<li>Cancellation of <code>run_process()</code> could very briefly leak
an orphan process.</li>
<li>Cancellation of <code>Process.aclose()</code> or
<code>run_process()</code> on Trio could leave
standard streams unclosed</li>
</ul>
<p>(PR by Ganden Schaffner)</p>
</li>
<li>
<p>Fixed <code>Process.stdin.aclose()</code>,
<code>Process.stdout.aclose()</code>, and
<code>Process.stderr.aclose()</code> not including a checkpoint on
asyncio (PR by Ganden
Schaffner)</p>
</li>
<li>
<p>Fixed documentation on how to provide your own typed attributes</p>
</li>
</ul>
<p><strong>4.2.0</strong></p>
<ul>
<li>
<p>Add support for <code>byte</code>-based paths in
<code>connect_unix</code>, <code>create_unix_listeners</code>,
<code>create_unix_datagram_socket</code>, and
<code>create_connected_unix_datagram_socket</code>. (PR by
Lura Skye)</p>
</li>
<li>
<p>Enabled the <code>Event</code> and <code>CapacityLimiter</code>
classes to be instantiated outside an
event loop thread</p>
</li>
<li>
<p>Broadly improved/fixed the type annotations. Among other things, many
functions and
methods that take variadic positional arguments now make use of PEP 646
<code>TypeVarTuple</code> to allow the positional arguments to be
validated by static type
checkers. These changes affected numerous methods and functions,
including:</p>
<ul>
<li><code>anyio.run()</code></li>
<li><code>TaskGroup.start_soon()</code></li>
<li><code>anyio.from_thread.run()</code></li>
<li><code>anyio.from_thread.run_sync()</code></li>
<li><code>anyio.to_thread.run_sync()</code></li>
<li><code>anyio.to_process.run_sync()</code></li>
<li><code>BlockingPortal.call()</code></li>
<li><code>BlockingPortal.start_task_soon()</code></li>
<li><code>BlockingPortal.start_task()</code></li>
</ul>
<p>(also resolves
<code>[#560](agronholm/anyio#560)
&lt;https://github.com/agronholm/anyio/issues/560&gt;</code>_)</p>
</li>
<li>
<p>Fixed various type annotations of <code>anyio.Path</code> to match
Typeshed:</p>
</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/agronholm/anyio/commit/437a7e310925a962cab4a58fcd2455fbcd578d51"><code>437a7e3</code></a>
Bumped up the version</li>
<li><a
href="https://github.com/agronholm/anyio/commit/1ce32e5c9e4789154b783150785db0fdaf35e0c1"><code>1ce32e5</code></a>
Updated the upload/download artifact actions</li>
<li><a
href="https://github.com/agronholm/anyio/commit/d39c83780d1465a43c5c52b07fea23d65bb73cb5"><code>d39c837</code></a>
[pre-commit.ci] pre-commit autoupdate (<a
href="https://redirect.github.com/agronholm/anyio/issues/690">#690</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/ba48ea8ae18b6e2895af20104d187ee22a9a551c"><code>ba48ea8</code></a>
Added the network marker to some tests that need DNS (<a
href="https://redirect.github.com/agronholm/anyio/issues/687">#687</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/5426f7bf1e01066ac7111a090d76a4ff5d48e25f"><code>5426f7b</code></a>
Remove conditionals and workarounds for Python interpreter versions 3.7
and o...</li>
<li><a
href="https://github.com/agronholm/anyio/commit/7565f3162706f9eca503f5ef353113076135f95c"><code>7565f31</code></a>
[pre-commit.ci] pre-commit autoupdate (<a
href="https://redirect.github.com/agronholm/anyio/issues/684">#684</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/137de708f40262e959d9d43178dda600432da56b"><code>137de70</code></a>
Fixed documentation on providing custom typed attributes (<a
href="https://redirect.github.com/agronholm/anyio/issues/683">#683</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/8b8806c745482c1d39708d012b2c90e4c9e92c6f"><code>8b8806c</code></a>
Fixed typo (<a
href="https://redirect.github.com/agronholm/anyio/issues/681">#681</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/1e60219d95bb6a3c1ddf0618634f8ee3eb566037"><code>1e60219</code></a>
Fixed <code>run_process()</code> and
<code>open_process().__aexit__</code> leaking an orphan proces...</li>
<li><a
href="https://github.com/agronholm/anyio/commit/3f14df89fe4c6d5edebae345a95d04c30334bba2"><code>3f14df8</code></a>
[pre-commit.ci] pre-commit autoupdate (<a
href="https://redirect.github.com/agronholm/anyio/issues/676">#676</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/agronholm/anyio/compare/4.2.0...4.3.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=anyio&package-manager=pip&previous-version=4.2.0&new-version=4.3.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
mkjpryor pushed a commit to stackhpc/azimuth that referenced this issue Mar 5, 2024
Bumps [anyio](https://github.com/agronholm/anyio) from 4.2.0 to 4.3.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/agronholm/anyio/releases">anyio's
releases</a>.</em></p>
<blockquote>
<h2>4.3.0</h2>
<ul>
<li>
<p>Added support for the Python 3.12 <code>walk_up</code> keyword
argument in <code>anyio.Path.relative_to()</code> (PR by Colin
Taylor)</p>
</li>
<li>
<p>Fixed passing <code>total_tokens</code> to
<code>anyio.CapacityLimiter()</code> as a keyword argument not working
on the <code>trio</code> backend (<a
href="https://redirect.github.com/agronholm/anyio/issues/515">#515</a>)</p>
</li>
<li>
<p>Fixed <code>Process.aclose()</code> not performing the minimum level
of necessary cleanup when cancelled. Previously:</p>
<ul>
<li>Cancellation of <code>Process.aclose()</code> could leak an orphan
process</li>
<li>Cancellation of <code>run_process()</code> could very briefly leak
an orphan process.</li>
<li>Cancellation of <code>Process.aclose()</code> or
<code>run_process()</code> on Trio could leave standard streams
unclosed</li>
</ul>
<p>(PR by Ganden Schaffner)</p>
</li>
<li>
<p>Fixed <code>Process.stdin.aclose()</code>,
<code>Process.stdout.aclose()</code>, and
<code>Process.stderr.aclose()</code> not including a checkpoint on
asyncio (PR by Ganden Schaffner)</p>
</li>
<li>
<p>Fixed documentation on how to provide your own typed attributes</p>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/agronholm/anyio/blob/master/docs/versionhistory.rst">anyio's
changelog</a>.</em></p>
<blockquote>
<h1>Version history</h1>
<p>This library adheres to <code>Semantic Versioning 2.0
&lt;http://semver.org/&gt;</code>_.</p>
<p><strong>4.3.0</strong></p>
<ul>
<li>
<p>Added support for the Python 3.12 <code>walk_up</code> keyword
argument in
<code>anyio.Path.relative_to()</code> (PR by Colin Taylor)</p>
</li>
<li>
<p>Fixed passing <code>total_tokens</code> to
<code>anyio.CapacityLimiter()</code> as a keyword argument
not working on the <code>trio</code> backend
(<code>[#515](agronholm/anyio#515)
&lt;https://github.com/agronholm/anyio/issues/515&gt;</code>_)</p>
</li>
<li>
<p>Fixed <code>Process.aclose()</code> not performing the minimum level
of necessary cleanup when
cancelled. Previously:</p>
<ul>
<li>Cancellation of <code>Process.aclose()</code> could leak an orphan
process</li>
<li>Cancellation of <code>run_process()</code> could very briefly leak
an orphan process.</li>
<li>Cancellation of <code>Process.aclose()</code> or
<code>run_process()</code> on Trio could leave
standard streams unclosed</li>
</ul>
<p>(PR by Ganden Schaffner)</p>
</li>
<li>
<p>Fixed <code>Process.stdin.aclose()</code>,
<code>Process.stdout.aclose()</code>, and
<code>Process.stderr.aclose()</code> not including a checkpoint on
asyncio (PR by Ganden
Schaffner)</p>
</li>
<li>
<p>Fixed documentation on how to provide your own typed attributes</p>
</li>
</ul>
<p><strong>4.2.0</strong></p>
<ul>
<li>
<p>Add support for <code>byte</code>-based paths in
<code>connect_unix</code>, <code>create_unix_listeners</code>,
<code>create_unix_datagram_socket</code>, and
<code>create_connected_unix_datagram_socket</code>. (PR by
Lura Skye)</p>
</li>
<li>
<p>Enabled the <code>Event</code> and <code>CapacityLimiter</code>
classes to be instantiated outside an
event loop thread</p>
</li>
<li>
<p>Broadly improved/fixed the type annotations. Among other things, many
functions and
methods that take variadic positional arguments now make use of PEP 646
<code>TypeVarTuple</code> to allow the positional arguments to be
validated by static type
checkers. These changes affected numerous methods and functions,
including:</p>
<ul>
<li><code>anyio.run()</code></li>
<li><code>TaskGroup.start_soon()</code></li>
<li><code>anyio.from_thread.run()</code></li>
<li><code>anyio.from_thread.run_sync()</code></li>
<li><code>anyio.to_thread.run_sync()</code></li>
<li><code>anyio.to_process.run_sync()</code></li>
<li><code>BlockingPortal.call()</code></li>
<li><code>BlockingPortal.start_task_soon()</code></li>
<li><code>BlockingPortal.start_task()</code></li>
</ul>
<p>(also resolves
<code>[#560](agronholm/anyio#560)
&lt;https://github.com/agronholm/anyio/issues/560&gt;</code>_)</p>
</li>
<li>
<p>Fixed various type annotations of <code>anyio.Path</code> to match
Typeshed:</p>
</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/agronholm/anyio/commit/437a7e310925a962cab4a58fcd2455fbcd578d51"><code>437a7e3</code></a>
Bumped up the version</li>
<li><a
href="https://github.com/agronholm/anyio/commit/1ce32e5c9e4789154b783150785db0fdaf35e0c1"><code>1ce32e5</code></a>
Updated the upload/download artifact actions</li>
<li><a
href="https://github.com/agronholm/anyio/commit/d39c83780d1465a43c5c52b07fea23d65bb73cb5"><code>d39c837</code></a>
[pre-commit.ci] pre-commit autoupdate (<a
href="https://redirect.github.com/agronholm/anyio/issues/690">#690</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/ba48ea8ae18b6e2895af20104d187ee22a9a551c"><code>ba48ea8</code></a>
Added the network marker to some tests that need DNS (<a
href="https://redirect.github.com/agronholm/anyio/issues/687">#687</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/5426f7bf1e01066ac7111a090d76a4ff5d48e25f"><code>5426f7b</code></a>
Remove conditionals and workarounds for Python interpreter versions 3.7
and o...</li>
<li><a
href="https://github.com/agronholm/anyio/commit/7565f3162706f9eca503f5ef353113076135f95c"><code>7565f31</code></a>
[pre-commit.ci] pre-commit autoupdate (<a
href="https://redirect.github.com/agronholm/anyio/issues/684">#684</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/137de708f40262e959d9d43178dda600432da56b"><code>137de70</code></a>
Fixed documentation on providing custom typed attributes (<a
href="https://redirect.github.com/agronholm/anyio/issues/683">#683</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/8b8806c745482c1d39708d012b2c90e4c9e92c6f"><code>8b8806c</code></a>
Fixed typo (<a
href="https://redirect.github.com/agronholm/anyio/issues/681">#681</a>)</li>
<li><a
href="https://github.com/agronholm/anyio/commit/1e60219d95bb6a3c1ddf0618634f8ee3eb566037"><code>1e60219</code></a>
Fixed <code>run_process()</code> and
<code>open_process().__aexit__</code> leaking an orphan proces...</li>
<li><a
href="https://github.com/agronholm/anyio/commit/3f14df89fe4c6d5edebae345a95d04c30334bba2"><code>3f14df8</code></a>
[pre-commit.ci] pre-commit autoupdate (<a
href="https://redirect.github.com/agronholm/anyio/issues/676">#676</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/agronholm/anyio/compare/4.2.0...4.3.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=anyio&package-manager=pip&previous-version=4.2.0&new-version=4.3.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants