FIXED This issue has been fixed by moving QApplication out of main().
Hi I’m trying to implement a web service that executes the JavaScript code of a given URL and gives back the final HTML. I’m using PyQt4 for JS processing and Django 1.4 web framework.
The problem is: the script always works in the command invite but when I integrate it to Django it works only the first time, after running the Django local server, then during the following executions it warns:
WARNING: QApplication was not created in the main() thread
QObject::startTimer: QTimer can only be used with threads started with QThread
and I got wrong results.
The problem is that I’m not using any thread…
Here is the script I’m using on Django (urlconf leads to this main fonction with the url given):
#!/usr/bin/env python
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
from time import time, sleep
app = QApplication(sys.argv)
def wait(app, secs=1):
deadline = time() + secs
while time() < deadline:
sleep(0)
app.processEvents()
def main(url):
# app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl(url))
wait(app, 15)
return web.page().mainFrame().toHtml().toUtf8()
Have you seen this before or tried to do something similar? Please help me with any information thank you
P.S. This is my first post here I hope everything is clear 🙂
EDIT The warnings are gone thanks to Rostyslav but I still have the sale issue.
Actually you use threads.
Django developments server uses threading by default. You can pass optional
--nothreadingparameter torunservercommand which is intended to disable using threads by server: