Repository: nvaccess/nvda

Issue:
Cannot reload plugins in NVDA snapshots
<!-- Please read the text in this edit field before filling it in.
Please thoroughly read NVDA's wiki article on how to fill in this template, including how to provide the required files.
Issues may be closed if the required information is not present.
https://github.com/nvaccess/nvda/blob/master/devDocs/githubIssueTemplateExplanationAndExamples.md
Please also note that the NVDA project has a Citizen and Contributor Code of Conduct which can be found at https://github.com/nvaccess/nvda/blob/master/CODE_OF_CONDUCT.md. NV Access expects that all contributors and other community members read and abide by the rules set out in this document while participating or contributing to this project. This includes creating or commenting on issues and pull requests. 

Each of the questions and sections below start with multiple hash symbols (#). Place your answers and information on the blank line below each question.
-->

### Steps to reproduce:
1. Install some add-ons an ensure they work.
2. Press NVDA+control+f3 or use the reload plugins option available under NVDA's tools menu.
3. Try to use add-ons.
### Actual behavior:
<!--
Use "Speak command keys" (NVDA+4) and speech viewer to copy and paste here. 
Use braille viewer to copy and paste here.
You may additionally include an explanation.
-->

Plugins are terminated, not reloaded. Note that, when pressing shift+control+q after reloading plugins,, message about eMule version is not reported.

shift+ctrl+q
Versión 0.50a de eMule lista
ctrl+NVDA+f3
Plugins reloaded
shift+ctrl+q

### Expected behavior:
Plugins should be reloaded, not just terminated.

shift+ctrl+q
Versión 0.50a de eMule lista
ctrl+NVDA+f3
Plugins reloaded
shift+ctrl+q
Versión 0.50a de eMule lista
<!--
Use "Speak command keys" (NVDA+4) and speech viewer to copy and paste here. 
Use braille viewer to copy and paste here.
You may additionally include an explanation.
-->
[nvda.log](https://github.com/nvaccess/nvda/files/10097680/nvda.log)

### NVDA logs, crash dumps and other attachments:

### System configuration
#### NVDA installed/portable/running from source:
Running from source

#### NVDA version:
source-master-85efa6d (2023.1.0.0)
#### Windows version:
Versión	10.0.22621 compilación 22621

#### Name and version of other software in use when reproducing the issue:
n/a
#### Other information about your system:
Windows in Spanish
### Other questions
#### Does the issue still occur after restarting your computer?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
nvda_snapshot_alpha-27190,85efa6d7 portable, with same behavior.
#### If NVDA add-ons are disabled, is your problem still occurring?
No, since the problem is related to add-ons.
#### Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Yes


Discussion:
This has been reported by other users.
See this `thread on the add-onsmailing list](https://nvda-addons.groups.io/g/nvda-addons/topic/95253295#19876)
Hi,

Er, @LeonardDer, is this possibly a regression from the work on add-on directories or braille/background thread splitting?

Thanks.
It could be. I'll have a look tomorrow.

Resolving patch:
diff --git a/source/appModuleHandler.py b/source/appModuleHandler.py
--- a/source/appModuleHandler.py
+++ b/source/appModuleHandler.py
@@ -341,6 +341,8 @@ def reloadAppModules():
 	for mod in mods:
 		del sys.modules[mod]
 	import appModules
+	from addonHandler.packaging import addDirsToPythonPackagePath
+	addDirsToPythonPackagePath(appModules)
 	initialize()
 	for entry in state:
 		pid = entry.pop("processID")
diff --git a/source/globalPluginHandler.py b/source/globalPluginHandler.py
--- a/source/globalPluginHandler.py
+++ b/source/globalPluginHandler.py
@@ -51,6 +51,8 @@ def reloadGlobalPlugins():
 	for mod in mods:
 		del sys.modules[mod]
 	import globalPlugins
+	from addonHandler.packaging import addDirsToPythonPackagePath
+	addDirsToPythonPackagePath(globalPlugins)
 	initialize()
 
 class GlobalPlugin(baseObject.ScriptableObject):


Test patch: