From: <Mar...@am...> - 2007-08-22 13:59:08
|
Hi All, This seems like a silly question, but what is the recommended way of programmatically shutting down an embedded InteractiveConsole if you cannot send it a CTRL+Z from the keyboard? I want to be able to open and close interpreters programmatically and I keep getting exceptions if I close the streams. But I can't seem to find a way to send a shutdown signal the the interpreter. Is there a way to do this that I am missing, or do I need to subclass InteractiveInterpreter and make my own console that looks for a certain event? Thanks, Mark. AMI Semiconductor - "Silicon Solutions for the Real World" NOTICE: This electronic message contains information that may be confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you received this electronic message in error, please notify the sender and delete the copy you received. |
From: <Mar...@am...> - 2007-08-22 14:13:05
|
Ah. Simply unhooking the UI console streams from the InteractiveConsole (setting them back to System.out and System.err) clears up my exceptions, but I am not sure I am actually killing the interpreter. What is the default exit function for PySystemState (called by cleanup())? Here is what I am currently doing when I dispose my console (this is in a UI where the user can open/close as many Jython consoles as they wish): interp.setOut(System.out); interp.setErr(System.err); interp.cleanup(); interp = null; (interp is an instance of InteractiveConsole) M. ---------------------------------------------------------- Mar...@am... Sent by: jyt...@li... 08/22/2007 10:00 AM To jyt...@li... cc Subject [Jython-users] How To Programmatically Shut Down InteractiveConsole Hi All, This seems like a silly question, but what is the recommended way of programmatically shutting down an embedded InteractiveConsole if you cannot send it a CTRL+Z from the keyboard? I want to be able to open and close interpreters programmatically and I keep getting exceptions if I close the streams. But I can't seem to find a way to send a shutdown signal the the interpreter. Is there a way to do this that I am missing, or do I need to subclass InteractiveInterpreter and make my own console that looks for a certain event? Thanks, Mark. AMI Semiconductor - "Silicon Solutions for the Real World" NOTICE: This electronic message contains information that may be confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you received this electronic message in error, please notify the sender and delete the copy you received. |
From: <Mar...@am...> - 2007-08-22 15:24:27
|
Sorry to keep replying to myself - but this is the best solution I have found. Please feel free to suggest a better one! ;o) // Unhook the streams from the console interp.setOut(System.out); interp.setErr(System.err); try { interp.push("\n\n"); interp.push("import sys"); interp.push("sys.exit(0)"); } catch (PyException exc) { if (!Py.matchException(exc, Py.SystemExit)) { throw exc; } } interp = null; M. ---------------------------------------------------------- Mar...@am... Sent by: jyt...@li... 08/22/2007 10:14 AM To jyt...@li... cc Subject Re: [Jython-users] How To Programmatically Shut Down InteractiveConsole Ah. Simply unhooking the UI console streams from the InteractiveConsole (setting them back to System.out and System.err) clears up my exceptions, but I am not sure I am actually killing the interpreter. What is the default exit function for PySystemState (called by cleanup())? Here is what I am currently doing when I dispose my console (this is in a UI where the user can open/close as many Jython consoles as they wish): interp.setOut(System.out); interp.setErr(System.err); interp.cleanup(); interp = null; (interp is an instance of InteractiveConsole) M. ---------------------------------------------------------- Mar...@am... Sent by: jyt...@li... 08/22/2007 10:00 AM To jyt...@li... cc Subject [Jython-users] How To Programmatically Shut Down InteractiveConsole Hi All, This seems like a silly question, but what is the recommended way of programmatically shutting down an embedded InteractiveConsole if you cannot send it a CTRL+Z from the keyboard? I want to be able to open and close interpreters programmatically and I keep getting exceptions if I close the streams. But I can't seem to find a way to send a shutdown signal the the interpreter. Is there a way to do this that I am missing, or do I need to subclass InteractiveInterpreter and make my own console that looks for a certain event? Thanks, Mark. AMI Semiconductor - "Silicon Solutions for the Real World" NOTICE: This electronic message contains information that may be confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you received this electronic message in error, please notify the sender and delete the copy you received. |
From: <ast...@gm...> - 2007-08-23 02:19:50
|
I'm not sure what exactly you want, but you can "exit" from a Jython console this way: >> import sys >> sys.exit() On 8/22/07, Mar...@am... <Mar...@am...> wrote: > > > Sorry to keep replying to myself - but this is the best solution I have > found. Please feel free to suggest a better one! ;o) > > // Unhook the streams from the console > interp.setOut(System.*out*); > interp.setErr(System.*err*); > *try* { > interp.push("\n\n"); > interp.push("import sys"); > interp.push("sys.exit(0)"); > } *catch* (PyException exc) { > *if* (!Py.*matchException*(exc, Py.*SystemExit*)) { > *throw* exc; > } > } > interp = *null*; > > M. > ---------------------------------------------------------- > > > > *Mar...@am...* > Sent by: jyt...@li... > > 08/22/2007 10:14 AM > To > jyt...@li... cc > > Subject > Re: [Jython-users] How To Programmatically Shut Down > InteractiveConsole > > > > > > > > Ah. Simply unhooking the UI console streams from the InteractiveConsole > (setting them back to System.out and System.err) clears up my exceptions, > but I am not sure I am actually killing the interpreter. What is the > default exit function for PySystemState (called by cleanup())? Here is what > I am currently doing when I dispose my console (this is in a UI where the > user can open/close as many Jython consoles as they wish): > > interp.setOut(System.*out*); > interp.setErr(System.*err*); > interp.cleanup(); > interp = *null*; > > (interp is an instance of InteractiveConsole) > > M. > ---------------------------------------------------------- > > > *Mar...@am...* > Sent by: jyt...@li... > > 08/22/2007 10:00 AM > > To > jyt...@li... cc > > Subject > [Jython-users] How To Programmatically Shut Down InteractiveConsole > > > > > > > > > > Hi All, > > This seems like a silly question, but what is the recommended way of > programmatically shutting down an embedded InteractiveConsole if you cannot > send it a CTRL+Z from the keyboard? I want to be able to open and close > interpreters programmatically and I keep getting exceptions if I close the > streams. But I can't seem to find a way to send a shutdown signal the the > interpreter. Is there a way to do this that I am missing, or do I need to > subclass InteractiveInterpreter and make my own console that looks for a > certain event? > > Thanks, > Mark. > > > AMI Semiconductor - "Silicon Solutions for the Real World" > NOTICE: > This electronic message contains information that may be confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you received this electronic message in error, please notify the sender and delete the copy you received. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: Charlie G. <cha...@gm...> - 2007-08-23 07:42:07
|
Hi Mark, There's nothing special that needs to be done to shutdown the interpreter. Calling cleanup just calls the exit function as you noted, and sys.exit does the same thing. By default, exit_func is None so nothing happens. After you've called cleanup, you can let garbage collection take its course. What exceptions are you seeing when you close the streams? What streams are these that you close? Charlie On 8/22/07, Mar...@am... <Mar...@am...> wrote: > > Sorry to keep replying to myself - but this is the best solution I have found. Please feel free to suggest a better one! ;o) > > // Unhook the streams from the console > interp.setOut(System.out); > interp.setErr(System.err); > try { > interp.push("\n\n"); > interp.push("import sys"); > interp.push("sys.exit(0)"); > } catch (PyException exc) { > if (!Py.matchException(exc, Py.SystemExit)) { > throw exc; > } > } > interp = null; > > M. > ---------------------------------------------------------- > > > > > Mar...@am... > Sent by: jyt...@li... > > 08/22/2007 10:14 AM > > To jyt...@li... > > cc > > > Subject Re: [Jython-users] How To Programmatically Shut Down InteractiveConsole > > > > > > > > > > Ah. Simply unhooking the UI console streams from the InteractiveConsole (setting them back to System.out and System.err) clears up my exceptions, but I am not sure I am actually killing the interpreter. What is the default exit function for PySystemState (called by cleanup())? Here is what I am currently doing when I dispose my console (this is in a UI where the user can open/close as many Jython consoles as they wish): > > interp.setOut(System.out); > interp.setErr(System.err); > interp.cleanup(); > interp = null; > > (interp is an instance of InteractiveConsole) > > M. > ---------------------------------------------------------- > > > > Mar...@am... > Sent by: jyt...@li... > > 08/22/2007 10:00 AM > > > To jyt...@li... > > cc > > > Subject [Jython-users] How To Programmatically Shut Down InteractiveConsole > > > > > > > > > > > Hi All, > > This seems like a silly question, but what is the recommended way of programmatically shutting down an embedded InteractiveConsole if you cannot send it a CTRL+Z from the keyboard? I want to be able to open and close interpreters programmatically and I keep getting exceptions if I close the streams. But I can't seem to find a way to send a shutdown signal the the interpreter. Is there a way to do this that I am missing, or do I need to subclass InteractiveInterpreter and make my own console that looks for a certain event? > > Thanks, > Mark. > > > AMI Semiconductor - "Silicon Solutions for the Real World" > NOTICE: > This electronic message contains information that may be confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you received this electronic message in error, please notify the sender and delete the copy you received. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: <Mar...@am...> - 2007-08-23 14:49:44
|
Thanks for the reply, Charlie. The exceptions I was seeing were not related to Jython but rather to Jython trying to write to streams in my GUI console that I had mistakenly closed before exiting the interpreter. I have another question however, now that I have my console going. I am trying to implement a command history like you get in the standard Jython console (your basic up arrow and down arrow functionality). It looks like you get this for free when you start a vanilla Jython console (if I run jython.bat for instance) but I can't find anywhere in the source that handles this. How is this supported? I see a class providing JLine support but I think this needs to be "turned on" with the JLine support jar being present as well. How is the basic command history functionality provided in Jython (where is the code)? Mark. ---------------------------------------------------------- "Charlie Groves" <cha...@gm...> Sent by: jyt...@li... 08/23/2007 03:46 AM To "Mar...@am..." <Mar...@am...> cc jyt...@li... Subject Re: [Jython-users] How To Programmatically Shut Down InteractiveConsole Hi Mark, There's nothing special that needs to be done to shutdown the interpreter. Calling cleanup just calls the exit function as you noted, and sys.exit does the same thing. By default, exit_func is None so nothing happens. After you've called cleanup, you can let garbage collection take its course. What exceptions are you seeing when you close the streams? What streams are these that you close? Charlie On 8/22/07, Mar...@am... <Mar...@am...> wrote: > > Sorry to keep replying to myself - but this is the best solution I have found. Please feel free to suggest a better one! ;o) > > // Unhook the streams from the console > interp.setOut(System.out); > interp.setErr(System.err); > try { > interp.push("\n\n"); > interp.push("import sys"); > interp.push("sys.exit(0)"); > } catch (PyException exc) { > if (!Py.matchException(exc, Py.SystemExit)) { > throw exc; > } > } > interp = null; > > M. > ---------------------------------------------------------- > > > > > Mar...@am... > Sent by: jyt...@li... > > 08/22/2007 10:14 AM > > To jyt...@li... > > cc > > > Subject Re: [Jython-users] How To Programmatically Shut Down InteractiveConsole > > > > > > > > > > Ah. Simply unhooking the UI console streams from the InteractiveConsole (setting them back to System.out and System.err) clears up my exceptions, but I am not sure I am actually killing the interpreter. What is the default exit function for PySystemState (called by cleanup())? Here is what I am currently doing when I dispose my console (this is in a UI where the user can open/close as many Jython consoles as they wish): > > interp.setOut(System.out); > interp.setErr(System.err); > interp.cleanup(); > interp = null; > > (interp is an instance of InteractiveConsole) > > M. > ---------------------------------------------------------- > > > > Mar...@am... > Sent by: jyt...@li... > > 08/22/2007 10:00 AM > > > To jyt...@li... > > cc > > > Subject [Jython-users] How To Programmatically Shut Down InteractiveConsole > > > > > > > > > > > Hi All, > > This seems like a silly question, but what is the recommended way of programmatically shutting down an embedded InteractiveConsole if you cannot send it a CTRL+Z from the keyboard? I want to be able to open and close interpreters programmatically and I keep getting exceptions if I close the streams. But I can't seem to find a way to send a shutdown signal the the interpreter. Is there a way to do this that I am missing, or do I need to subclass InteractiveInterpreter and make my own console that looks for a certain event? > > Thanks, > Mark. > > > AMI Semiconductor - "Silicon Solutions for the Real World" > NOTICE: > This electronic message contains information that may be confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you received this electronic message in error, please notify the sender and delete the copy you received. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users AMI Semiconductor - "Silicon Solutions for the Real World" NOTICE: This electronic message contains information that may be confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you received this electronic message in error, please notify the sender and delete the copy you received. |
From: Jeff E. <jem...@fr...> - 2007-08-23 14:54:46
|
Windows provides the command history when you run jython.bat. Mar...@am... wrote: > Thanks for the reply, Charlie. The exceptions I was seeing were not > related to Jython but rather to Jython trying to write to streams in my > GUI console that I had mistakenly closed before exiting the interpreter. > > I have another question however, now that I have my console going. I am > trying to implement a command history like you get in the standard Jython > console (your basic up arrow and down arrow functionality). It looks like > you get this for free when you start a vanilla Jython console (if I run > jython.bat for instance) but I can't find anywhere in the source that > handles this. How is this supported? I see a class providing JLine > support but I think this needs to be "turned on" with the JLine support > jar being present as well. How is the basic command history functionality > provided in Jython (where is the code)? > > Mark. > ---------------------------------------------------------- > > > > > "Charlie Groves" <cha...@gm...> > Sent by: jyt...@li... > 08/23/2007 03:46 AM > > To > "Mar...@am..." <Mar...@am...> > cc > jyt...@li... > Subject > Re: [Jython-users] How To Programmatically Shut Down InteractiveConsole > > > > > > > Hi Mark, > > There's nothing special that needs to be done to shutdown the > interpreter. Calling cleanup just calls the exit function as you > noted, and sys.exit does the same thing. By default, exit_func is > None so nothing happens. After you've called cleanup, you can let > garbage collection take its course. > > What exceptions are you seeing when you close the streams? What > streams are these that you close? > > Charlie > > On 8/22/07, Mar...@am... <Mar...@am...> wrote: >> Sorry to keep replying to myself - but this is the best solution I have > found. Please feel free to suggest a better one! ;o) >> // Unhook the streams from the console >> interp.setOut(System.out); >> interp.setErr(System.err); >> try { >> interp.push("\n\n"); >> interp.push("import sys"); >> interp.push("sys.exit(0)"); >> } catch (PyException exc) { >> if (!Py.matchException(exc, Py.SystemExit)) { >> throw exc; >> } >> } >> interp = null; >> >> M. >> ---------------------------------------------------------- >> >> >> >> >> Mar...@am... >> Sent by: jyt...@li... >> >> 08/22/2007 10:14 AM >> >> To jyt...@li... >> >> cc >> >> >> Subject Re: [Jython-users] How To Programmatically Shut Down > InteractiveConsole >> >> >> >> >> >> >> >> >> Ah. Simply unhooking the UI console streams from the > InteractiveConsole (setting them back to System.out and System.err) clears > up my exceptions, but I am not sure I am actually killing the interpreter. > What is the default exit function for PySystemState (called by > cleanup())? Here is what I am currently doing when I dispose my console > (this is in a UI where the user can open/close as many Jython consoles as > they wish): >> interp.setOut(System.out); >> interp.setErr(System.err); >> interp.cleanup(); >> interp = null; >> >> (interp is an instance of InteractiveConsole) >> >> M. >> ---------------------------------------------------------- >> >> >> >> Mar...@am... >> Sent by: jyt...@li... >> >> 08/22/2007 10:00 AM >> >> >> To jyt...@li... >> >> cc >> >> >> Subject [Jython-users] How To Programmatically Shut Down > InteractiveConsole >> >> >> >> >> >> >> >> >> >> Hi All, >> >> This seems like a silly question, but what is the recommended way of > programmatically shutting down an embedded InteractiveConsole if you > cannot send it a CTRL+Z from the keyboard? I want to be able to open and > close interpreters programmatically and I keep getting exceptions if I > close the streams. But I can't seem to find a way to send a shutdown > signal the the interpreter. Is there a way to do this that I am missing, > or do I need to subclass InteractiveInterpreter and make my own console > that looks for a certain event? >> Thanks, >> Mark. >> >> >> AMI Semiconductor - "Silicon Solutions for the Real World" >> NOTICE: >> This electronic message contains information that may be confidential or > privileged. The information is intended for the use of the individual or > entity named above. If you are not the intended recipient, please be aware > that any disclosure, copying, distribution or use of the contents of this > information is prohibited. If you received this electronic message in > error, please notify the sender and delete the copy you received. >> >> > ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Splunk Inc. >> Still grepping through log files to find problems? Stop. >> Now Search log events and configuration files using AJAX and a browser. >> Download your FREE copy of Splunk now >> http://get.splunk.com/ >> _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> https://lists.sourceforge.net/lists/listinfo/jython-users >> >> > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > > AMI Semiconductor - "Silicon Solutions for the Real World" > NOTICE: > This electronic message contains information that may be confidential or privileged. The information is intended for the use of the individual or entity named above. If you are not the intended recipient, please be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you received this electronic message in error, please notify the sender and delete the copy you received. > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |
From: Philip C. <cro...@se...> - 2007-08-23 15:02:48
Attachments:
Bag.java
|
Here is an example of setting up jython to use jline for history. This is a "terminal" based app, but using a gui is probably similar. Probably also worth looking at jline docs, http://jline.sourceforge.net/ Philip |