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

Importing Taichi without stdout output #8334

Closed
rmmr opened this issue Aug 26, 2023 · 1 comment
Closed

Importing Taichi without stdout output #8334

rmmr opened this issue Aug 26, 2023 · 1 comment
Assignees
Labels
question Question on using Taichi

Comments

@rmmr
Copy link

rmmr commented Aug 26, 2023

Importing taichi as follows

import taichi as ti

the stdout receives [Taichi] version 1.6.0, llvm 15.0.4, commit f1c6fbbd, linux, python 3.10.12

I tried to wrap the import as follows:

with open(os.devnull, "w") as devnull:
    with contextlib.redirect_stdout(devnull):
        import taichi as ti

Then the stdout receives [I 08/26/23 11:30:47.825 17489] [shell.py:_shell_pop_print@23] Graphical python shell detected, using wrapped sys.stdout

Is there any way to prevent this?

@rmmr rmmr added the question Question on using Taichi label Aug 26, 2023
@lin-hitonami
Copy link
Contributor

We do not have a flag to disable it now. However you can delete this line in your Taichi package, then it won't print the header.

_print_taichi_header()

lin-hitonami pushed a commit that referenced this issue Nov 27, 2023
Issue: #8334 

### Brief Summary

Add a flag to disable Taichi header print. One can set
``os.environ['ENABLE_TAICHI_HEADER_PRINT'] = False`` to disable the
header print.

<!--
copilot:summary
-->
### <samp>🤖[[deprecated]](https://githubnext.com/copilot-for-prs-sunset)
Generated by Copilot at 65548e0</samp>

Add an option to disable Taichi header printing using an environment
variable. Modify `python/taichi/_lib/utils.py` to implement the option.

### Walkthrough

<!--
copilot:walkthrough
-->
### <samp>🤖[[deprecated]](https://githubnext.com/copilot-for-prs-sunset)
Generated by Copilot at 65548e0</samp>

* Add a conditional check to enable or disable the Taichi header
printing
([link](https://github.com/taichi-dev/taichi/pull/8413/files?diff=unified&w=0#diff-46daba8967b07b778d2090c80d91720ba234f327d62bc475b2fb956c9f04223dL172-R173))
* Use an environment variable `ENABLE_TAICI_HEADER_PRINT` to control the
check
([link](https://github.com/taichi-dev/taichi/pull/8413/files?diff=unified&w=0#diff-46daba8967b07b778d2090c80d91720ba234f327d62bc475b2fb956c9f04223dL172-R173))

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
bobcao3 pushed a commit that referenced this issue Jun 23, 2024
Issue: #8334 

### Brief Summary

The previous code #8413 had no effect because the value in os.environ
can only be a string. This pull request will enable users to disable the
Taichi header print by setting one of the following ways:

- os.environ['ENABLE_TAICHI_HEADER_PRINT'] = 'False'
- os.environ['ENABLE_TAICHI_HEADER_PRINT'] = 'FALSE'
- os.environ['ENABLE_TAICHI_HEADER_PRINT'] = 'F'
- os.environ['ENABLE_TAICHI_HEADER_PRINT'] = '0'

### Walkthrough

copilot:walkthrough

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question on using Taichi
Projects
Status: Done
Development

No branches or pull requests

2 participants