[PyQt] PyQt5 and Spyder 3.3.2 Conflict, Beautiful Soup, <kernel died, restarting>
Kyle Altendorf
sda at fstab.net
Sun Mar 24 18:48:08 GMT 2019
I don't believe your code guarantees that app.quit() gets called. But
I'm a bit vague on the details myself. I would start by adding a print
before the quit call and then see if the failures to run a second time
in the same kernel correspond to cases where the print doesn't happen.
I would also rework it to avoid the inheritance. Not because
inheritance is evil but because it serves no purpose here if I am
reading correctly.
Is the qt application even meant to be used twice? It's a very global
thing. Might want to app = QApplication.instance() and then if that's
none create an app for scenarios where you have a long-running
interpreter. Though the multi-use of it is even more of a concern then.
Do read the docs carefully about having multiple or reused app
instances. I think that's bad.
Maybe a side note, maybe not. There's selenium and requests-html if you
are just looking for a js-capable url getter/processor.
Cheers,
-kyle
On March 24, 2019 1:29:51 PM EDT, Gene Ensor <g_ensor at hotmail.com>
wrote:
> Kyle,
>
> Many thanks for your response! However your questions are many levels
> above my head. Please note I would be more than happy to run code and
> report on the output to you or the pseudo forum in an effort to move
> forward. Additional information as follows:
>
> On a second run I get:
>
> <kernel died, restarting>
> or
> <An error occurred while starting the kernel>
>
> Anaconda "Python 3.7.1 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10 |
> Spyder 3.3.2
>
> Spyder>help>dependencies
>
> IPython >=4.0 : 7.2.0 (OK)
> cython >=0.21 : 0.29.2 (OK)
> jedi >=0.9.0 : 0.13.2 (OK)
> matplotlib >=2.0.0: 3.0.2 (OK)
> nbconvert >=4.0 : 5.4.0 (OK)
> numpy >=1.7 : 1.15.4 (OK)
> pandas >=0.13.1 : 0.23.4 (OK)
> pycodestyle >=2.3 : 2.4.0 (OK)
> pyflakes >=0.6.0 : 2.0.0 (OK)
> pygments >=2.0 : 2.3.1 (OK)
> pylint >=0.25 : 2.2.2 (OK)
> qtconsole >=4.2.0 : 4.4.3 (OK)
> rope >=0.9.4 : 0.11.0 (OK)
> sphinx >=0.6.6 : 1.8.2 (OK)
> sympy >=0.7.3 : 1.3 (OK)
>
> Thanks again!
>
> Gene
>
> -----Original Message-----
> From: Kyle Altendorf <sda at fstab.net>
> Sent: Saturday, March 23, 2019 7:59 PM
> To: pyqt at riverbankcomputing.com; Gene Ensor <g_ensor at hotmail.com>;
> pyqt at riverbankcomputing.com
> Subject: Re: [PyQt] PyQt5 and Spyder 3.3.2 Conflict, Beautiful Soup,
> <An error occurred while starting the kernel>
>
> Have you verified in those cases that the app exit is being called? If
> you fail out because of an exception it won't be. I would really
> manage the app outside your class. (Does Qt really force you to
> inherit here?). Then you can try/finally to make sure it gets exited
> even after a python exception. Or even make yourself a context
> manager.
>
> Cheers,
> -kyle
>
> On March 23, 2019 9:28:13 PM EDT, Gene Ensor <g_ensor at hotmail.com>
> wrote:
>> Team,
>>
>> Per
>>
>> https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithu
>> b.com%2Fspyder-ide%2Fspyder%2Fwiki%2FHow-to-run-PyQt-applications-withi
>> n-Spyder&data=02%7C01%7C%7Cefe8a2de6a6a456bbd4708d6affc3ef3%7C84df9
>> e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636889895249156064&sdata=kKve
>> zNdJY%2BYL2%2F4Yjyq%2BQLdN%2BgtR%2BVyRRwK8vADUi0I%3D&reserved=0
>>
>> I believe I have the following problem:
>>
>> "The most common problem when running a PyQt multiple times inside
>> Spyder is that a QApplication instance remains in the namespace of the
>
>> IPython console kernel after the first run. In other words, when you
>> try to re-run your application, you already have a QApplication
>> instance initialized."
>>
>> Hence when ran a second time I get "An error occurred while starting
>> the kernel". However I am not skilled enough to update the below code
>
>> to behave correctly my environment.
>>
>> Anaconda "Python 3.7.1 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10 |
>> Spyder 3.3.2
>>
>> Can you assist? Thanks!
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> import sys
>> from PyQt5.QtWebEngineWidgets import QWebEnginePage from
>> PyQt5.QtWidgets import QApplication, QDialog from PyQt5.QtCore import
>> QUrl, QCoreApplication
>>
>> import bs4 as bs
>> import urllib.request
>>
>>
>> class Page(QWebEnginePage):
>> def __init__(self, url):
>> # PyQt5 has the "minimal" platform plugin.
>> # To use it, modify the argv passed to QApplication to include
>> # ['-platform', 'minimal'].
>> self.app = QApplication(sys.argv)
>> QWebEnginePage.__init__(self)
>> self.html = ''
>> self.loadFinished.connect(self._on_load_finished)
>> self.load(QUrl(url))
>> self.app.exec_()
>>
>> def _on_load_finished(self):
>> self.html = self.toHtml(self.Callable)
>> print('Load finished')
>>
>> def Callable(self, html_str):
>> self.html = html_str
>> self.app.quit()
>>
>>
>> def main():
>> page =
> Page('https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpythonprogramming.net%2Fparsememcparseface%2F&data=02%7C01%7C%7Cefe8a2de6a6a456bbd4708d6affc3ef3%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636889895249156064&sdata=uuqunuxYJs1xxShwscoSbBVf%2Bb1Su6A2l5zn%2FhCBsK8%3D&reserved=0')
>> soup = bs.BeautifulSoup(page.html, 'html.parser')
>> js_test = soup.find('p', class_='jstest')
>> print(js_test.text) #fixed
>> # output should be "Look at you shinin!"
>> if __name__ == '__main__': main()
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the PyQt
mailing list