views:

70

answers:

2

web_view_crash.py

import sys

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import *

app = QApplication(sys.argv)
view = QWebView()
view.settings().setAttribute(QWebSettings.JavascriptEnabled, True)
view.load(QUrl('infinite_loop.html'))
view.show()
app.exec_()

infinite_loop.html

<script>
    while(true) {
        document.write('infinite loop...')}
</script>

I want to fix this from my python code, without touching the javascript. Can I kill the javascript somehow?

Edit: Both files are local.

A: 

??? This really makes no sense at all. The Javascript file is an infinite loop. You cannot "kill" the page code from the server. It's just impossible - especially when the browser is stuck running CPU-bound Javascript.

Maybe that Javascript file was just supplied as an example, but it doesn't really matter. If you know that you've got a page that's broken in that way, you have to fix the page.

Pointy
I'm running local javascript. There's no server here.I tried upgrading my PyQt. After I did that I get a popup message saying something like, "This script seems to have a problem, do you want to terminate it?" That would suggest there's a way to stop the execution. But if I click yes, nothing happens...Chrome seems to handle this pretty well. It keeps trying to load the page in one tab, but the browser doesn't become unresponsive. I'd like to do something like that in my gui app. I'm just looking for a workaround here.
Jesse Aldridge
How are you looking at the page? If it's via a browser, there's a server, regardless of whether it's local or not. It's absolutely not possible for your Python code to intervene.
Pointy
A: 

Pointy has no idea what he is talking about ;-) I'm also looking for something similar to this...in fact, I'm looking for a way to allow the script to run without prompting that message.

Jarred