question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OSError: [Errno 25] Inappropriate ioctl for device when running in pytest

See original GitHub issue

A project of mine uses alive-progress. I updated from 1.6.2 to 2.1.0 and the above error was raised when I ran my tests. I tried running the test in different terminals - iterm2, vscode and pycharm but got the same exception. Below is the stack trace for the same.

tests/test_base.py::test_pipeline_with_default_reader
  /Users/saifkazi/Desktop/preprocessy/venv/lib/python3.9/site-packages/_pytest/threadexception.py:75: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-1

  Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner
      self.run()
    File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 892, in run
      self._target(*self._args, **self._kwargs)
    File "/Users/saifkazi/Desktop/preprocessy/venv/lib/python3.9/site-packages/alive_progress/core/progress.py", line 112, in run
      alive_repr(next(spinner_player))
    File "/Users/saifkazi/Desktop/preprocessy/venv/lib/python3.9/site-packages/alive_progress/core/progress.py", line 123, in alive_repr
      run.last_len = print_cells(fragments, term.cols(), run.last_len, _term=term)
    File "/Users/saifkazi/Desktop/preprocessy/venv/lib/python3.9/site-packages/alive_progress/utils/terminal/tty.py", line 32, in cols
      return os.get_terminal_size()[0]
  OSError: [Errno 25] Inappropriate ioctl for device

The code that uses alive-progress

def process(self):
        """Method that executes the pipeline sequentially."""
        self.print_info()
        with alive_bar(
            len(self.steps),
            title="Pipeline Stages",
            enrich_print=False,
            force_tty=True,
        ) as bar:
            print("\nProcessing...\n")
            for step in self.steps:
                step(self.params)
                print(
                    f"==> Completed Stage: {stringcase.sentencecase(step.__name__)}\n"
                )
                bar()
        print(
            Fore.GREEN + "\nPipeline Completed Successfully\n" + Style.RESET_ALL
        )

The test for above

def test_pipeline_with_default_reader():
    df = pd.DataFrame({"A": np.arange(1, 100), "B": np.arange(1, 100)})
    _ = df.to_csv("./datasets/configs/dataset.csv", index=False)

    params = {
        "col_1": "A",
        "col_2": "B",
        "test_size": 0.2,
    }

    pipeline = BasePipeline(
        train_df_path="./datasets/configs/dataset.csv",
        steps=[times_two, squared, split],
        params=params,
    )
    pipeline.process()

    assert "train_df" in pipeline.params.keys()

Version Numbers

Python - 3.8, 3.9 alive-progress - 2.1.0

From what I could debug, this has something to do with utils/terminal/tty.py.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rsalmeicommented, Oct 27, 2021

Nice, as I thought… And great that it works with the default value of force_tty. But unfortunately I don’t know of any fix for that. I even tried to search about it, but couldn’t find anything relevant…

No, not at all! You won’t miss out anything! This param exists just as a workaround for terminals that do not report themselves as “interactive”, such as Pycharm’s terminal and Jupyter Notebook. So, if you’re running your software anywhere else, it won’t make any difference 👍

I’ll close this ticket than, but feel free to reply if you want.

0reactions
Saif807380commented, Oct 27, 2021

Yes, the test broke on the first line itself as you mentioned. Is there a workaround to this? Setting force_tty = None, fixes the running of tests. But are there any side effects to doing so? Right now with force_tty at its default value, satisfies all my use cases, but is there some feature that I’ll miss out on by doing this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

IOError: [Errno 25] Inappropriate ioctl for device - Stack Overflow
This would happen if stdout isn't a terminal (e,g,, redirecting to a file or run as a subprocess and its a pipe). There...
Read more >
When trying to run 'poetry shell' on github CI, I get a (25 ...
The inappropriate ioctl is because Poetry is using a library to manipulate the pty, and this fails when stdout is not a pty....
Read more >
Handling OSError exception in Python - GeeksforGeeks
OSError is a built-in exception in Python and serves as the error class for the os ... OSError: [Errno 25] Inappropriate ioctl for...
Read more >
Changelog — pytest documentation
#10060: When running with --pdb , TestCase.tearDown is no longer called for tests when the class has been skipped via unittest.skip or pytest.mark.skip...
Read more >
pytest Documentation - Read the Docs
pytest will run all files of the form test_*.py or *_test.py in the current directory and its subdirectories. More generally,.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found