Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(282)

Issue 2810: SystemRestart exception to restart the interpreter (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
17 years, 10 months ago by Leo Soto M.
Modified:
16 years, 10 months ago
Base URL:
https://jython.svn.sourceforge.net/svnroot/jython/branches/asm
Visibility:
Public.

Description

Context: 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 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+93 lines, -30 lines) Patch
Lib/test/test_urllib2_localnet.py View 1 chunk +1 line, -1 line 2 comments Download
src/org/python/core/FunctionThread.java View 1 chunk +4 lines, -10 lines 0 comments Download
src/org/python/core/Py.java View 2 chunks +12 lines, -0 lines 1 comment Download
src/org/python/core/PyTableCode.java View 1 chunk +6 lines, -0 lines 0 comments Download
src/org/python/core/exceptions.java View 1 chunk +3 lines, -0 lines 0 comments Download
src/org/python/modules/thread/thread.java View 4 chunks +23 lines, -2 lines 0 comments Download
src/org/python/util/jython.java View 8 chunks +44 lines, -17 lines 2 comments Download

Messages

Total messages: 4
Leo Soto M.
Issue created.
17 years, 10 months ago (2008-08-04 02:45:00 UTC) #1
Nicholas Riley
http://codereview.appspot.com/2810/diff/1/8 File Lib/test/test_urllib2_localnet.py (right): http://codereview.appspot.com/2810/diff/1/8#newcode229 Line 229: PORT = 8765 Seems to be an unrelated ...
17 years, 10 months ago (2008-08-04 02:59:41 UTC) #2
Leo Soto M.
http://codereview.appspot.com/2810/diff/1/8 File Lib/test/test_urllib2_localnet.py (right): http://codereview.appspot.com/2810/diff/1/8#newcode229 Line 229: PORT = 8765 On 2008/08/04 02:59:41, Nicholas Riley ...
17 years, 10 months ago (2008-08-04 03:11:53 UTC) #3
fwierzbicki
17 years, 10 months ago (2008-08-04 13:42:57 UTC) #4
http://codereview.appspot.com/2810/diff/1/5
File src/org/python/core/Py.java (right):

http://codereview.appspot.com/2810/diff/1/5#newcode215
Line 215: 
We should comment this as being experimental.

http://codereview.appspot.com/2810/diff/1/7
File src/org/python/util/jython.java (right):

http://codereview.appspot.com/2810/diff/1/7#newcode281
Line 281: /**
I like that this has been broken out into its own method.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b