Sublime Forum

Auto reloading of python module files used by plugin

#21

In case anyone else is having issues implementing this & needs a temporary workaround, I wrote:

  • a plugin command that executes window.run_command("exit"). Ctrl + Shift + Alt + Win + F15

  • an AutoHotkey script that sends the above key-combo and then reloads SublimeText. Ctrl + Shift + Alt + Win + S

 

The windows reload instantly, but there’s about a 5-second delay for ST to be fully functional since ALL plugins & modules have to reload.
( maybe more or less depending on the amount of plugins you have installed )

 

 

@ Plugin.py

	def EXIT ( window ):
		window.run_command ( "exit" )

 
@ Plugin/Default.sublime-keymap

	{ "keys": ["ctrl+shift+alt+super+f15"], "command": "my_plugin", "args": { "MODE": "EXIT" }  },

 
@ restart_SublimeText.ahk

#Persistent
#SingleInstance Force

#IfWinActive ahk_class PX_WINDOW_CLASS

	^+!#s::

		Send, ^+!#{F15}

		Sleep, 200
		Run, "C:\Program Files\Sublime Text 3\sublime_text.exe"

	Return
0 Likes

How to restart Sublime Text 2?
[MODULE] module_loader : Reload Modules & Dependencies WITHOUT Restarting Sublime Text
#22

@wbond

 
I managed to put a solution together after looking further into imp, os, & sys.

The script uses Globals() as a parameter and dynamically loads modules to the plugin’s Globals via pluginGlobals[ moduleName ] = imp.load_module (...)

Implementation is concise, requiring only 3 lines in the plugin.

 
Also, I believe that I solved the issue you mentioned of having to reload modules in a particular order by looping over the load process twice.
( This hasn’t been extensively tested, but I’m assuming it should work.  I don’t really have anything to test it with - there’s only one module with dependencies in Parkour v1 and it’s working fine. )

Loading modules twice would not be ideal for something like Package Control, where it would have a significant impact on performance due to the amount of modules, but for most plugins it shouldn’t be an issue.
 

Please let me know if you see any potential issues or circumstances where the script might not work. :slightly_smiling:
 



 
See this thread for more info:

[MODULE] module_loader : Reload Modules & Dependencies WITHOUT Restarting Sublime Text

0 Likes

#23

@fico have you looked at [MODULE] module_loader : Reload Modules & Dependencies WITHOUT Restarting Sublime Text ?

0 Likes