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

How to ignore TrioDeprecationWarning only #1833

Closed
shamrin opened this issue Dec 24, 2020 · 2 comments
Closed

How to ignore TrioDeprecationWarning only #1833

shamrin opened this issue Dec 24, 2020 · 2 comments

Comments

@shamrin
Copy link
Contributor

shamrin commented Dec 24, 2020

I couldn't find a way to ignore TrioDeprecationWarning only. I get the warning while using recent trio-asyncio release (0.11), on Python 3.9:

.../trio_asyncio/_base.py:20: TrioDeprecationWarning: trio.hazmat is deprecated since Trio 0.15.0; use trio.lowlevel instead (https://github.com/python-trio/trio/issues/476)
  from trio.hazmat import wait_for_child

(The warning seems to be fixed in the master: python-trio/trio-asyncio#87. But the point about ignoring TrioDeprecationWarning still stands.)

  1. I've tried python -W ignore::trio.TrioDeprecationWarning ..., but I got Invalid -W option ignored: invalid module name: 'trio' error. There is an open Python bug about it.

  2. I've tried PYTHONPATH=/full/path/to/trio work-around to fix the above, but it fails with core dump: Fatal Python error: init_sys_streams: can't initialize sys standard streams. There is another open Python bug about it.

  3. I've tried import warnings; warnings.filterwarnings("ignore") at my entry module, but it doesn't do anything for me.

Is there any way to ignore TrioDeprecationWarning only?

@asmeurer
Copy link

asmeurer commented Jan 6, 2021

import warnings; warnings.filterwarnings("ignore") works for me. I am using the following

import warnings

import trio
with warnings.catch_warnings():
    warnings.filterwarnings('ignore', category=trio.TrioDeprecationWarning)
    import trio_asyncio

The filter has to be enabled before trio_asyncio is imported. If this is difficult for whatever reason, a workaround would be to manually import trio.hazmat to trigger the warning. Since imports are cached in Python, the warning will only be triggered once.

(of course, with all that being said, a release of trio-asyncio that fixes this would be nice)

@shamrin
Copy link
Contributor Author

shamrin commented Jan 8, 2021

@asmeurer Thank you for the solution!

(And, we have just released trio-asyncio.)

@shamrin shamrin closed this as completed Jan 8, 2021
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

No branches or pull requests

2 participants