skariel / webalchemy

Modern web development with Python
MIT License
346 stars 21 forks source link

Server does not update client code correctly #128

Closed joaoventura closed 10 years ago

joaoventura commented 10 years ago

I have a file with the hello world example:

class HellowWorldApp:
    def initialize(self, **kwargs):
        self.rdoc = kwargs['remote_document']
        self.rdoc.body.element(h1='Hello World!!!').events.add(click=self.clicked, translate=True)
        self.rdoc.body.element(h2='--------------')
        self.rdoc.stylesheet.rule('h1').style(
            color='#FF0000',
            marginLeft='75px',
            marginTop='75px',
            background='#00FF00'
        )

    def clicked(self):
        self.textContent = self.textContent[1:]
        rpc(self.handle_click_on_backend, 'some message', 'just so you see how to pass paramaters')

    def handle_click_on_backend(self, sender_id, m1, m2):
        self.rdoc.body.element(h1=m1+m2)

and another one which starts the server

from webalchemy import server
from helloworld import HellowWorldApp

server.run(HellowWorldApp)

The problem is that, when I make changes to the HelloWorldApp, only some propagate correctly to the client. For instance, changes in this line:

self.rdoc.body.element(h1='Goodbye World!!!').events.add(click=self.clicked, translate=True)

propagates correctly to the client. However, if I change the contents on functions which are to be propagated to the client, such as:

def clicked(self):
    #self.textContent = self.textContent[1:]
    #rpc(self.handle_click_on_backend, 'some message', 'just so you see how to pass paramaters')
    pass

this does not go the client as is, but returns the first version (without comments). It seems that it is cached somewhere. The server process has to be restarted to apply the changes.

This behavior occurs in Firefox and Chrome (latest as in Ubuntu 13.04)..

skariel commented 10 years ago

This issue was introduced when using inspect.getsource() for translation with Pythonium. Turns out the result of getsource() is not updated after a reload() unless linecache.clearcache() is called after the reload.

Issue is now solved.

joaoventura commented 10 years ago

I've tested, it is working fine!