pythonpython-3.xwindows-subsystem-for-linuxpython-webbrowser

Error "tcgetpgrp failed: Not a tty" using python3 to open web browser


Here's the breakdown of my Windows WSL environment:

I have a super simple Python program I'm using to open a web page in my default browser.

Here is my code:

import webbrowser

webbrowser.open('https://github.com')

When I run this from my terminal the webpage opens up as expected, but I also get this error in the terminal:

tcgetpgrp failed: Not a tty

When my terminal displays this message, the cursor goes down to the next line and it looks like a process is hung or something. To be able to use the terminal I have to Ctrl+C to get it to give me the command prompt.

I looked for answers and everything I could find has to do with using Jupyter or PHP but I'm not using either of them, I'm just using plain old Python to try and open the browser.

Can anyone tell me what the issue is here and how to fix this/prevent it from happening?


Solution

  • Yes, I can also reproduce it from the Python (and IPython) REPL on Ubuntu under WSL. I don't get the "lockup" that requires Ctrl+C when running interactively, at least.

    I'll theorize on the "why". Most of this I can confirm myself, but the last bullet below is still a bit of a mystery to me:

    As a workaround, either: