Commit 0f2fd16d authored by Just van Rossum's avatar Just van Rossum

Hm, I never checked in my incomplete "run with interpreter" mods. UI is there...

Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
parent 6508c7c7
...@@ -17,10 +17,11 @@ import marshal ...@@ -17,10 +17,11 @@ import marshal
import regex import regex
try: try:
# experimental microthread support import Wthreading
import uthread2
except ImportError: except ImportError:
uthread2 = None haveThreading = 0
else:
haveThreading = Wthreading.haveThreading
_scriptuntitledcounter = 1 _scriptuntitledcounter = 1
_wordchars = string.letters + string.digits + "_" _wordchars = string.letters + string.digits + "_"
...@@ -109,6 +110,10 @@ class Editor(W.Window): ...@@ -109,6 +110,10 @@ class Editor(W.Window):
self.run_as_main = self.settings["run_as_main"] self.run_as_main = self.settings["run_as_main"]
else: else:
self.run_as_main = 0 self.run_as_main = 0
if self.settings.has_key("run_with_interpreter"):
self.run_with_interpreter = self.settings["run_with_interpreter"]
else:
self.run_with_interpreter = 0
self._threadstate = (0, 0) self._threadstate = (0, 0)
self._thread = None self._thread = None
...@@ -151,6 +156,7 @@ class Editor(W.Window): ...@@ -151,6 +156,7 @@ class Editor(W.Window):
self.settings["fontsettings"] = self.editgroup.editor.getfontsettings() self.settings["fontsettings"] = self.editgroup.editor.getfontsettings()
self.settings["tabsize"] = self.editgroup.editor.gettabsettings() self.settings["tabsize"] = self.editgroup.editor.gettabsettings()
self.settings["run_as_main"] = self.run_as_main self.settings["run_as_main"] = self.run_as_main
self.settings["run_with_interpreter"] = self.run_with_interpreter
def get(self): def get(self):
return self.editgroup.editor.get() return self.editgroup.editor.get()
...@@ -220,6 +226,8 @@ class Editor(W.Window): ...@@ -220,6 +226,8 @@ class Editor(W.Window):
("Save options", self.domenu_options), ("Save options", self.domenu_options),
'-', '-',
('\0' + chr(self.run_as_main) + 'Run as __main__', self.domenu_toggle_run_as_main), ('\0' + chr(self.run_as_main) + 'Run as __main__', self.domenu_toggle_run_as_main),
#('\0' + chr(self.run_with_interpreter) + 'Run with Interpreter', self.domenu_toggle_run_with_interpreter),
#'-',
('Modularize', self.domenu_modularize), ('Modularize', self.domenu_modularize),
('Browse namespace', self.domenu_browsenamespace), ('Browse namespace', self.domenu_browsenamespace),
'-'] '-']
...@@ -237,6 +245,12 @@ class Editor(W.Window): ...@@ -237,6 +245,12 @@ class Editor(W.Window):
def domenu_toggle_run_as_main(self): def domenu_toggle_run_as_main(self):
self.run_as_main = not self.run_as_main self.run_as_main = not self.run_as_main
self.run_with_interpreter = 0
self.editgroup.editor.selchanged = 1
def domenu_toggle_run_with_interpreter(self):
self.run_with_interpreter = not self.run_with_interpreter
self.run_as_main = 0
self.editgroup.editor.selchanged = 1 self.editgroup.editor.selchanged = 1
def showbreakpoints(self, onoff): def showbreakpoints(self, onoff):
...@@ -476,28 +490,52 @@ class Editor(W.Window): ...@@ -476,28 +490,52 @@ class Editor(W.Window):
if self._threadstate == (0, 0): if self._threadstate == (0, 0):
self._run() self._run()
else: else:
uthread2.globalLock() lock = Wthreading.Lock()
self._thread.raiseException(KeyboardInterrupt) lock.acquire()
if self._thread.isPaused(): self._thread.postException(KeyboardInterrupt)
if self._thread.isBlocked():
self._thread.start() self._thread.start()
uthread2.globalUnlock() lock.release()
def _run(self): def _run(self):
if self.run_with_interpreter:
if self.editgroup.editor.changed:
import EasyDialogs
import Qd; Qd.InitCursor()
save = EasyDialogs.AskYesNoCancel('Save %s before running?' % self.title, 1)
if save > 0:
if self.domenu_save():
return
elif save < 0:
return
if not self.path:
raise W.AlertError, "Can't run unsaved file"
self._run_with_interpreter()
else:
pytext = self.editgroup.editor.get() pytext = self.editgroup.editor.get()
globals, file, modname = self.getenvironment() globals, file, modname = self.getenvironment()
self.execstring(pytext, globals, globals, file, modname) self.execstring(pytext, globals, globals, file, modname)
def _run_with_interpreter(self):
interp_path = os.path.join(sys.exec_prefix, "PythonInterpreter")
if not os.path.exists(interp_path):
raise W.AlertError, "Can't find interpreter"
import findertools
XXX
def runselection(self): def runselection(self):
if self._threadstate == (0, 0): if self._threadstate == (0, 0):
self._runselection() self._runselection()
elif self._threadstate == (1, 1): elif self._threadstate == (1, 1):
self._thread.pause() self._thread.block()
self.setthreadstate((1, 2)) self.setthreadstate((1, 2))
elif self._threadstate == (1, 2): elif self._threadstate == (1, 2):
self._thread.start() self._thread.start()
self.setthreadstate((1, 1)) self.setthreadstate((1, 1))
def _runselection(self): def _runselection(self):
if self.run_with_interpreter:
raise W.AlertError, "Can't run selection with Interpreter"
globals, file, modname = self.getenvironment() globals, file, modname = self.getenvironment()
locals = globals locals = globals
# select whole lines # select whole lines
...@@ -571,8 +609,8 @@ class Editor(W.Window): ...@@ -571,8 +609,8 @@ class Editor(W.Window):
else: else:
cwdindex = None cwdindex = None
try: try:
if uthread2 and uthread2.currentThread() is not None: if haveThreading:
self._thread = uthread2.Thread(file, self._thread = Wthreading.Thread(os.path.basename(file),
self._exec_threadwrapper, pytext, globals, locals, file, self.debugging, self._exec_threadwrapper, pytext, globals, locals, file, self.debugging,
modname, self.profiling) modname, self.profiling)
self.setthreadstate((1, 1)) self.setthreadstate((1, 1))
...@@ -1082,13 +1120,14 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0, ...@@ -1082,13 +1120,14 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
return return
try: try:
if debugging: if debugging:
if uthread2: if haveThreading:
uthread2.globalLock() lock = Wthreading.Lock()
lock.acquire()
PyDebugger.startfromhere() PyDebugger.startfromhere()
uthread2.globalUnlock() lock.release()
else: else:
PyDebugger.startfromhere() PyDebugger.startfromhere()
elif not uthread2: elif not haveThreading:
MacOS.EnableAppswitch(0) MacOS.EnableAppswitch(0)
try: try:
if profiling: if profiling:
...@@ -1105,23 +1144,25 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0, ...@@ -1105,23 +1144,25 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
else: else:
exec code in globals, locals exec code in globals, locals
finally: finally:
if not uthread2: if not haveThreading:
MacOS.EnableAppswitch(-1) MacOS.EnableAppswitch(-1)
except W.AlertError, detail: except W.AlertError, detail:
raise W.AlertError, detail raise W.AlertError, detail
except (KeyboardInterrupt, BdbQuit): except (KeyboardInterrupt, BdbQuit):
pass pass
except: except:
if uthread2: if haveThreading:
uthread2.globalLock() import continuation
lock = Wthreading.Lock()
lock.acquire()
if debugging: if debugging:
sys.settrace(None) sys.settrace(None)
PyDebugger.postmortem(sys.exc_type, sys.exc_value, sys.exc_traceback) PyDebugger.postmortem(sys.exc_type, sys.exc_value, sys.exc_traceback)
return return
else: else:
tracebackwindow.traceback(1, filename) tracebackwindow.traceback(1, filename)
if uthread2: if haveThreading:
uthread2.globalUnlock() lock.release()
if debugging: if debugging:
sys.settrace(None) sys.settrace(None)
PyDebugger.stop() PyDebugger.stop()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment