Yes it will work for simple scripts but it might not work for more complex setups where data is being stored. In anycase it will not work for things that have been packaged in a module. Also it will not work very well if you have a persistent gui and some datamodel in the backend or are developing a node, in which case you need to engineer your code to account for reloading.
Suppose you have a simple object like this (yeah its pointless):
class StorageUnit(object):
def __init__(self, data_in):
self.data=data_in
Now say you create data elsewhere and store it in global list for example like this:
DATASTORE = [StorageUnit("foo"), StorageUnit("bar")]
if you later change the code to:
class StorageUnit(object):
def __init__(self, data_in):
self.data=data_in
def delete_data(self):
self.data=None
Now if you proceed doing,
psource(classfile)
DATASTORE[0].delete_data()
then you get an error. See the code you showed does not handle the CHANGIG of internal states of variables. Just new objects get this behaviour. Likewise if you change a subscript of the main script then also it does not do anything because it reloads the main only. You would need to do it recursively.
But in reality unless ALL your code is either really simple or designed from day one to account for this its a freaking pain in the ass. Its just better to restart the app because the error conditions you get are nontrivial. Presumably if your scipt needs a submodules then its nontrivial to test.
So say this elsewhere that relys on StorageUnit is in a separate file then suddenly that file still makes old style classes while maya global context makes new ones. So you would need to load the file with the class definition, all files that point to this file (after the class has been reloaded), and then update all instances in the whole memory universe.