PythonScript
PythonScript copied to clipboard
console.run() can cause a crash when used in a callback function
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])
- Create a new file or open a file
- Run test.py
- Close a file
- Notepad++ locks up
sounds like threading issues, I would vote for marking console.run with notAllowedInCallback like for example FindText
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.
Still an issue, tested on Windows 7 Professional (64-bit) Notepad++ v7.8.1 (64-bit) PythonScript 1.5.1.0
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.
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.