DescriptionContext: code "autoreloading"[1] on webapp dev-servers, such as Django. Problem: This kind of servers uses a forking/respawning strategy, which is very costly for us (on startup time and loosing HotSpot optimizations). It is interesting to see how this "autoreloaders" work. I know the django one[2], but I'm quite sure that the others are quite similar: * There is one "main supervisor". It just forks and wait the child process to exit. If it exits with a special status code (the value `3` is used on django), then the child it is spawned again. * The "runner", which is the process spawned by the "supervisor". It runs the main code on a thead, while constantly checking for changes on __file__'s of loaded modules. If a modification is detected, it exits with the special code that will make the "supervisor" to spawn the "runner" again. This gave me the idea that would be good to start supporting this strategy, obviously without the exit()/spawnve() bits. So I've implemented it by making the jython command line interpreter (jython.java) work as the "supervisor", by recognizing a new special exception: SystemRestart. This exception must be raised on the main thread. On other threads it have the same effect as SystemExit (i.e, exits the thread) There are a few problems with this approach, such as the possibility that not all running threads are stopped. Also, this isn't complete auto-restarting, because the "runner" component is not included on Jython. Anyway, it is quite easy to adapt existing "runners" to work on Jython[3]. Thus, by now, this is targeted for dev-servers scenarios and not meant for mission-critical problems. [1] I use quotes because it is not "reloading" in the sense of reimporting the changed code and continue the execution, but simply restarting the interpreter when some loaded module is changed. [2] http://code.djangoproject.com/browser/django/trunk/django/utils/autoreload.py [3] http://pylonshq.com/pasties/913 Patch Set 1
Created: 1 year, 3 months ago
MessagesTotal messages: 4
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||