Bug 402670 - Krita not responding in scripter after "quit()"
Summary: Krita not responding in scripter after "quit()"
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Scripting (other bugs)
Version First Reported In: 4.1.7
Platform: Microsoft Windows Microsoft Windows
: NOR crash
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-28 21:38 UTC by Martins
Modified: 2019-01-16 09:43 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
Freezed window after reproducing bug (7.85 KB, image/png)
2018-12-28 21:38 UTC, Martins
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martins 2018-12-28 21:38:19 UTC
Created attachment 117158 [details]
Freezed window after reproducing bug

SUMMARY


STEPS TO REPRODUCE
1. OPEN Scripter FROM "Tools" tab (Tools->Scripts->Scripter)
2. ENTER "quit()" in line 1 
3. RUN script

OBSERVED RESULT
Main window disappears,
while "Scripter - Krita" window freezes until user closes it manually
(though other times it just crashes).

EXPECTED RESULT
An Error in scripting shell

SOFTWARE/OS VERSIONS
Windows: 10 
Qt Version: 5.9.3

ADDITIONAL INFORMATION

Krita
  Version: 4.1.7

Qt
  Version (compiled): 5.9.3
  Version (loaded): 5.9.3

OS Information
  Build ABI: x86_64-little_endian-llp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: winnt
  Kernel Version: 10.0.17134
  Pretty Productname: Windows 10 (10.0)
  Product Type: windows
  Product Version: 10

OpenGL Info
  **OpenGL not initialized**
Comment 1 Halla Rempt 2018-12-28 21:55:50 UTC
Oh gosh, I'm not sure that's actually doable...
Comment 2 Martins 2018-12-28 22:12:10 UTC
(In reply to Boudewijn Rempt from comment #1)
> Oh gosh, I'm not sure that's actually doable...

From what I know quit() exits python( and goes back in command prompt if you launched python interpreter from cmd) so it should be unallowed command
Comment 3 Halla Rempt 2018-12-28 23:33:54 UTC
Yeah... But I don't know how we could remove that from the interpreter. Maybe it's just one the things people shouldn't do.
Comment 4 Rebecca Breu 2018-12-29 09:46:12 UTC
All that the quit and exit functions do is raise a SystemExit Exception that can be caught. Here's an example of how to do that on the embedding level:

http://www.myoddweb.com/2016/03/02/preventing-embedded-python-from-killing-your-app/

This would prevent any plugin to kill Krita with raising a SystemExit. Additionally, it would probably be a good idea to have the Scripter Plugin catch the exception itself on the Python level and simply close itself gracefully.

I haven't got around to compiling Krita myself yet, otherwise I'd play around with it myself.
Comment 5 Rebecca Breu 2019-01-04 14:19:10 UTC
I've submitted a patch that fixes the problem from the Scripter side: 
https://phabricator.kde.org/D17962

This still doesn't solve the problem of other Python Plugins raising a SystemExit and crashing Krita. I had both Segfaults and Sigabort with my version compiled in docker, but I don't understand the C++ side of things enough to know what's going on.
Comment 6 Halla Rempt 2019-01-16 09:43:28 UTC
Git commit e5ee9c48a3fd09da4bf73863228cc90a77726529 by Boudewijn Rempt.
Committed on 16/01/2019 at 09:42.
Pushed by rempt into branch 'master'.

Catch SystemExit Exception in Scripter
Differential Revision:https://phabricator.kde.org/D17962

Patch by Rebecca Breu, thanks!

M  +3    -0    plugins/python/scripter/ui_scripter/actions/runaction/runaction.py

https://commits.kde.org/krita/e5ee9c48a3fd09da4bf73863228cc90a77726529