« Return to Thread: Reloading of django views.py in modjy

Re: Reloading of django views.py in modjy

by Leo Soto M. :: Rate this Message:

Reply to Author | View in Thread

On Tue, Jun 16, 2009 at 12:23 PM, David Jensen<david.lgj@...> wrote:

> Hi all,
>
> I'm new here so if this is the wrong place for this question don't
> hesitate to yell at me :-)
>
> I'm trying to run django inside a WAR file with modjy on a JBoss 4.2.2
> Application server. (Next step is to integrate it into  a jboss seam
> project)
> The deployment time isn't great so I'm trying to get jython/modjy to
> reload my django application on change of a source file, as in the
> development server of django.
>
> I tried a lot of things. modjy will reload application.py on
> modification, so I tried to manually reload my views.py. Something
> like:
>
> def handler(environ, start_response):
>    os.putenv("DJANGO_SETTINGS_MODULE", "clean.settings")
>    h = wsgi.WSGIHandler()
>    import hello.views
>    reload(hello.views)
>    return h(environ, start_response)
>
> Didn't work.

First, I'm not familiar with modjy's reloading logic. But I can shed
some light on some of your questions.

First, unfortunately reload(foo) isn't enough as a reload strategy. It
will make Jython to recompile the module, will update it's entry on
sys.modules and will *return* the updated module. But if other modules
have a binding with the old module (which is what import do!), such
bindings won't be refreshed.

So, what's happening here is that Django holds a reference to the
non-updated hello.views module.


> So I tried further to remove the views$py.class file, and
> indeed it get's compiled if I remove it manually and touch
> application.py causing modjy to reload it and in turn triggers my
> import.
> An judging by changing filesize of views$py.class it would seem it's
> the updated views.py it compiles, but it still runs the old code!

That supports my explanation given above.

[...]
> So basically:
>  1) Has anyone done anything like this?
>  2) Why does it not execute the compile code? (is it a java thing?)
>  3) Am I barking up the wrong tree?

I don't have good answers here. If you already have discarded the
usage of the development server (jython manage.py runserver), I'd like
to hear why. Perhaps we can improve it and solve your problem.

But my take on the issue is that modjy's reloading strategy is falling
short on your use case and should be improved. If you fill an issue on
<http://bugs.jython.org> (so this doesn't get forgotten) you will
probably be helping to make Jython better!
--
Leo Soto M.
http://blog.leosoto.com

------------------------------------------------------------------------------
_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users

 « Return to Thread: Reloading of django views.py in modjy