Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS problem on start #374

Closed
pohmelie opened this issue May 5, 2017 · 5 comments
Closed

JS problem on start #374

pohmelie opened this issue May 5, 2017 · 5 comments

Comments

@pohmelie
Copy link

pohmelie commented May 5, 2017

Ubuntu 16.04 x64, Firefox, flexx-master

My develop flow with flexx right now is:

  1. Code.
  2. F5 in browser.
  3. Test.
  4. Go to 1.

But at some point when I hit F5 in browser after app restart my app won't start and I see in python console:

[I 13:51:43 flexx.app] Asset store collected 2 new modules.
[13:51:43] Using selector: EpollSelector
[I 13:51:43 flexx.app] Serving apps at http://localhost:49190/
[I 13:51:43 flexx.app] Starting Flexx event loop.
[I 13:51:47 flexx.app] Asset store collected 27 new modules.
[W 13:51:47 flexx.event] Event type "stats" does not exist. Use "!stats" or "!foo.bar.stats" to suppress this warning.
[13:51:47] 200 GET /Hubble/ (127.0.0.1) 55.91ms
[13:51:47] 200 GET /flexx/assets/shared/reset.css (127.0.0.1) 3.37ms
[13:51:47] 200 GET /flexx/assets/shared/flexx-core.js (127.0.0.1) 1.02ms
[13:51:47] 101 GET /flexx/ws/Hubble (127.0.0.1) 0.39ms
[I 13:51:47 flexx.app] New session Hubble eqHSzHWRxIRtk3fWVWEXXtSf
[E 13:51:47 flexx.app] JS - TypeError: flexx.classes.TimePlot is undefined (stack trace in browser console)
[E 13:51:47 flexx.app] JS - TypeError: flexx.classes.Hubble is not a constructor (stack trace in browser console)
[E 13:51:47 flexx.app] JS - TypeError: flexx.instances.Hubble1 is undefined (stack trace in browser console)
[E 13:51:47 flexx.app] JS - TypeError: flexx.instances.Hubble1 is undefined (stack trace in browser console)
[E 13:51:47 flexx.app] JS - TypeError: flexx.instances.Hubble1 is undefined (stack trace in browser console)
[E 13:51:47 flexx.app] JS - TypeError: flexx.instances.Hubble1 is undefined (stack trace in browser console)
[E 13:51:47 flexx.app] JS - TypeError: flexx.instances.Hubble1 is undefined (stack trace in browser console)
[E 13:51:47 flexx.app] JS - TypeError: flexx.instances.Hubble1 is undefined (stack trace in browser console)
[E 13:51:47 flexx.app] JS - TypeError: flexx.classes.TimePlot is not a constructor (stack trace in browser console)
[E 13:51:47 flexx.app] JS - TypeError: flexx.instances.TimePlot8 is undefined (stack trace in browser console)
[E 13:51:47 flexx.app] JS - Error: ValueError:HBoxPanel7.children must all be widget objects. (stack trace in browser console)
...

And so on. Big list of identical errors about my widgets(?). In browser console I see:

unreachable code after return statement[Learn More]  flexx-core.js:1070:4
Flexx: Initializing  flexx-core.js:754:9
Socket opened with session id eqHSzHWRxIRtk3fWVWEXXtSf  flexx-core.js:892:9
"TypeError: flexx.classes.TimePlot is undefined
 @ http://localhost:49190/flexx/assets/shared/krontech.gemini.hubble.js:21:1
define @ http://localhost:49190/flexx/assets/shared/flexx-core.js:43:15
 @ http://localhost:49190/flexx/assets/shared/krontech.gemini.hubble.js:7:1
Flexx.prototype.command @ http://localhost:49190/flexx/assets/shared/flexx-core.js:995:13
Flexx.prototype._process_commands @ http://localhost:49190/flexx/assets/shared/flexx-core.js:950:13"  flexx-core.js:929:9
"TypeError: flexx.classes.Hubble is not a constructor
 @ http://localhost:49190/flexx/assets/shared/flexx-core.js line 987 > eval:1:27
Flexx.prototype.command @ http://localhost:49190/flexx/assets/shared/flexx-core.js:987:9
Flexx.prototype._process_commands @ http://localhost:49190/flexx/assets/shared/flexx-core.js:950:13"  flexx-core.js:929:9
"TypeError: flexx.instances.Hubble1 is undefined
 @ http://localhost:49190/flexx/assets/shared/flexx-core.js line 987 > eval:1:1
Flexx.prototype.command @ http://localhost:49190/flexx/assets/shared/flexx-core.js:987:9
Flexx.prototype._process_commands @ http://localhost:49190/flexx/assets/shared/flexx-core.js:950:13"  flexx-core.js:929:9
"TypeError: flexx.instances.Hubble1 is undefined
 @ http://localhost:49190/flexx/assets/shared/flexx-core.js line 987 > eval:1:1
Flexx.prototype.command @ http://localhost:49190/flexx/assets/shared/flexx-core.js:987:9
Flexx.prototype._process_commands @ http://localhost:49190/flexx/assets/shared/flexx-core.js:950:13"  flexx-core.js:929:9
"TypeError: flexx.instances.Hubble1 is undefined
 @ http://localhost:49190/flexx/assets/shared/flexx-core.js line 987 > eval:1:47
Flexx.prototype.command @ http://localhost:49190/flexx/assets/shared/flexx-core.js:987:9
Flexx.prototype._process_commands @ http://localhost:49190/flexx/assets/shared/flexx-core.js:950:13"  flexx-core.js:929:9
"TypeError: flexx.classes.TimePlot is not a constructor
 @ http://localhost:49190/flexx/assets/shared/flexx-core.js line 987 > eval:1:29
Flexx.prototype.command @ http://localhost:49190/flexx/assets/shared/flexx-core.js:987:9
Flexx.prototype._process_commands @ http://localhost:49190/flexx/assets/shared/flexx-core.js:950:13"  flexx-core.js:929:9
"TypeError: flexx.instances.TimePlot8 is undefined
 @ http://localhost:49190/flexx/assets/shared/flexx-core.js line 987 > eval:1:1
Flexx.prototype.command @ http://localhost:49190/flexx/assets/shared/flexx-core.js:987:9
Flexx.prototype._process_commands @ http://localhost:49190/flexx/assets/shared/flexx-core.js:950:13"  flexx-core.js:929:9
"Error: ValueError:HBoxPanel7.children must all be widget objects.
...
Flexx.prototype._process_commands @ http://localhost:49190/flexx/assets/shared/flexx-core.js:950:13"  flexx-core.js:929:9
"TypeError: flexx.instances.Hubble1 is undefined
 @ http://localhost:49190/flexx/assets/shared/flexx-core.js line 987 > eval:1:1
Flexx.prototype.command @ http://localhost:49190/flexx/assets/shared/flexx-core.js:987:9
Flexx.prototype._process_commands @ http://localhost:49190/flexx/assets/shared/flexx-core.js:950:13"  flexx-core.js:929:9
Flexx server says hi  flexx-core.js:982:9

The problem is coming and going away with unknown reasons, definitely this does not depends of my python code, since sometimes it goes away without any code changes.

@pohmelie
Copy link
Author

pohmelie commented May 5, 2017

More to say. Even if I did not change my code at all and just restart the app, then sometimes this errors appear.

@pohmelie pohmelie changed the title Caching problem (?) JS problem on start May 5, 2017
@almarklein
Copy link
Member

The spew of TypeError: flexx.classes.TimePlot is undefined for when an exception occurs during loading of a module, causing none of the classes to exist. But in this case there does not seem to be such an exception (it should be one of the first ones logged, if its there). So perhaps this is indeed a caching problem.

Does it also happen when you press F5 while keeping the Python process, or only with a Python restart with a browser refresh?

@pohmelie
Copy link
Author

pohmelie commented May 8, 2017

@almarklein actually, I missed one big detail. I'm trying this out with asyncio loop as mentioned in #373. Problems can go from here.

causing none of the classes to exist

I tried wireshark to see what breaks, but packets are identical by order in all cases. It looks like races or even more looks like "dict order randomness" bug. I saw this few times, when code breaks if keys in dict are in some «unexpected» order.

Does it also happen when you press F5 while keeping the Python process, or only with a Python restart with a browser refresh?

If I start python process «unsuccessfully», then page will never load. Any F5 hit will cause same error to console. Same with successful start, if I start process and page is ok, then I can refresh it as much as I want, everything is fine.

@pohmelie
Copy link
Author

Ok, I bisect the problem. And it is not about asyncio. The problem is custom widgets and subclass.

from flexx import ui, app


class TimePlot(ui.PlotWidget):
    pass


class NetSpeedPlot(TimePlot):
    pass


class Foo(ui.Widget):
    def init(self):
        ui.Label(text="foo")


def main():
    app.App(Foo).serve()
    try:
        app.start()
    except KeyboardInterrupt:
        app.stop()


if __name__ == "__main__":
    main()

If you run this code couple of times, then you see, that half of times you will not see "foo" label and console will show you

[I 16:49:28 flexx.app] Asset store collected 2 new modules.
[I 16:49:29 flexx.app] Serving apps at http://localhost:49190/
[I 16:49:29 flexx.app] Starting Flexx event loop.
[I 16:49:30 flexx.app] Asset store collected 27 new modules.
assets/shared/reset.css
assets/shared/flexx-core.js
[I 16:49:30 flexx.app] New session Foo ga9g8lvPl8RgYAwYLx0aHdwV
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot read property 'prototype' of undefined (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: flexx.classes.Foo is not a constructor (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot set property '_sync_props' of undefined (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot read property '_set_prop_from_py' of undefined (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot read property '_set_prop_from_py' of undefined (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot read property '_set_prop_from_py' of undefined (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot read property '_set_prop_from_py' of undefined (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot read property 'init' of undefined (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot read property '_new_event_type_hook' of undefined (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot read property '_set_event_types_py' of undefined (stack trace in browser console)
[E 16:49:35 flexx.app] JS - Uncaught TypeError: Cannot read property '_init_handlers' of undefined (stack trace in browser console)

But, if you comment NetSpeedPlot definition, then everything will be fine. So, it looks like some «magic» is happen (or not happen) under.

@almarklein almarklein added this to the v0.5 milestone Oct 13, 2017
@almarklein
Copy link
Member

Closing this, because #408 changed a lot in the code related to this issue, and everything seems to be working. Please re-open if it persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants