Reloading a project without restarting Python

49 views
Skip to first unread message

Tobia Conforto

unread,
Apr 7, 2012, 2:32:38 PM4/7/12
to Django users
Hi all

I'm developing a portlet bridge in Jython, to enable developing J2EE
portlets in Django, and I need to include a reload-on-code-change
feature, to aid in development.

Unfortunately, the way django.utils.autoreload works, by triggering a
complete restart of the Jython interpreter, has huge memory and thread
leaks in Jython. It would appear that there is no clean way to unload
a
Jython interpreter from the JVM once it's been started. (For backing
of
this assertion, see my latest post on the jython-users list.)

Therefore I'd like to know if there is a way to reload a Django
project
from within Python, without restarting the interpreter itself.

For normal development it would be enough to reload the project's own
models, views, urls, admin, form, middleware and such classes. Some
of
the settings could be kept, if it made the reloading simpler, such as
filesystem paths, database connections, installed apps and middleware.

Any changes to the standard library, Django, and in general any code
that is not part of the current project's module could be ignored. If
a developer needs to reload that, he can very well restart everything!

Does anybody have any advice on how to do this?

-Tobia

Bill Freeman

unread,
Apr 8, 2012, 9:01:21 PM4/8/12
to django...@googlegroups.com

I don't believe that this is possible. While you can apply the reload()
built in function to a module, other modules which have references to,
for example, class objects (an instance has a reference __class__ to
its class object), will still be referring to the old instance. Finding all
references and fixing them is a hard, if not impossible, problem.

Reply all
Reply to author
Forward
0 new messages