How to resume a program (or exit) after opening a web browser?

I am creating a small Python program that calls a module webbrowserto open a URL. Opening a URL works great.

My problem is that as soon as this line of code is reached, the problem is not responding. How to get a program to continue this line of code and continue execution? Below the problematic line is the problematic line, in context:

if viewinbrowser == "y":
    print "I can definitely do that. Loading URL now!"
    webbrowser.open_new(url)
    print "Exiting..."
    sys.exit()

The program does not reach the execution print "Exiting..."that I added because I noticed that for some reason the program did not leave the if statement.

I run this program from the command line if it is important. Edit: I run on Kubuntu 9.04 i386 using KDE 4.3 via backports. I use Firefox 3.5 as the default browser declared in the system settings for KDE, and it is correctly called a program. (At least a new tab opens in Firefox with the right URL, I believe that this is the desired functionality.) / Edit

In addition, I assume that this problem will occur with almost any external call, but I am very new to Python and do not know the terminology for searching on this site. (The search for "python webbrowser" did not bring anything useful.) So, I apologize if it has already been discussed under a different heading!

Any suggestions?

+3
3

, , . , Windows, , , UNIX- . .

pid = os.fork()
if pid:
    # we are the parent, continue on
    print "This runs in a separate process from the else clause."

else:
    #child runs browser then quits.
    webbrowser.open_new(url)
    print "Exiting..."
    sys.exit()
+4

, , .

  • MacOSX - True . , .
  • Linux ( X) - . , True.
  • Linux ( X) - Konquerer ( ). True . .

, Windows, , , fork. , webbrowser fork , Windows. , , -, :

>>> import webbrowser
>>> import threading
>>> x=lambda: webbrowser.open_new('http://scompt.com')
>>> t=threading.Thread(target=x)
>>> t.start()
+4

webbrowser (-), ( "" ) . . (A) , - ( , fork() ) , - .

0

Source: https://habr.com/ru/post/1712968/


All Articles