PythonScript icon indicating copy to clipboard operation
PythonScript copied to clipboard

console.run() can cause a crash when used in a callback function

Open cellarmation opened this issue 9 years ago • 5 comments

I am using PythonScript 1.0.8.0 with Notepad++ v6.8.6 on Windows 10. I have found that use of console.run() from a callback function can cause Notepad++ to crash when triggered. The following example causes a crash, but the same command works when called directly.

test.py:

def fileBeforeCloseCallback(args):
    console.run('cmd.exe /?')
notepad.callback(fileBeforeCloseCallback, [NOTIFICATION.FILEBEFORECLOSE])
  1. Create a new file or open a file
  2. Run test.py
  3. Close a file
  4. Notepad++ locks up

cellarmation avatar Dec 06 '15 18:12 cellarmation

sounds like threading issues, I would vote for marking console.run with notAllowedInCallback like for example FindText

Ekopalypse avatar Oct 27 '19 21:10 Ekopalypse

I needs to be checked what is the current state for this. Maybe fixed with https://github.com/bruderstein/PythonScript/pull/51 and the GIL fixes there.

chcg avatar Oct 28 '19 01:10 chcg

Still an issue, tested on Windows 7 Professional (64-bit) Notepad++ v7.8.1 (64-bit) PythonScript 1.5.1.0

Ekopalypse avatar Oct 28 '19 10:10 Ekopalypse

I assume marking console.run with notAllowedInCallback will prevent the crash by blocking use of run?

I was originally trying to use Python Script as a way to control an external tool/script on tab open/close events. At the time I looked into this there was no easy way to hook into when Notepad++ closed a tab without writing a full plugin. So when I saw that PythonScript had callbacks for these events I thought it could be a great time saver. Obviously this might be a use case you are not that interested in supporting, just thought a bit of context might be useful.

cellarmation avatar Oct 29 '19 07:10 cellarmation

I assume marking console.run with notAllowedInCallback will prevent the crash by blocking use of run?

Yes, that is the idea.

If I understand correctly, you did use notifications to execute a batch of cmd commands/exes? In theory one should be able to do this via subprocess module as well I guess with the advantage to have even more control for automation.

But just to be clear, if there is one out who as has the time and knowledge to make this work for callbacks, I'm fine with it too. Unfortunately I'm not the one - lacking c++ knowledge.

Ekopalypse avatar Oct 29 '19 11:10 Ekopalypse