#7997: Use ast to replace display hook hack, and replace pexpect based
WorksheetProcess classes with Pipe-based ones
-------------------------------------+--------------------------------------
   Reporter:  acleone                |       Owner:  was         
       Type:  enhancement            |      Status:  needs_review
   Priority:  major                  |   Milestone:              
  Component:  notebook               |    Keywords:              
     Author:  Alex Leone, Tim Dumol  |    Upstream:  N/A         
   Reviewer:                         |      Merged:              
Work_issues:                         |  
-------------------------------------+--------------------------------------
Changes (by timdumol):

 * cc: boothby (added)
  * status:  needs_work => needs_review


Old description:

> See http://docs.python.org/library/ast.html#ast.NodeTransformer
>
> Replace any Expr node in the ast tree with a function call to
> {{{
> def __print_if_not_none(expr):
>     if expr is not None:
>         print expr
> }}}
> An Expr node is anything like
> {{{
> 123
> do_foo()
> for i in range(10):
>     i
> }}}
> Which will be replaced by
> {{{
> __print_if_not_none(123)
> __print_if_not_none(do_foo())
> for i in range(10):
>     __print_if_not_none(i)
> }}}
> Which will output
> {{{
> 123
> 0
> 1
> ...
> 9
> }}}

New description:

 Please see ticket:7997:comment:10 for more details.

--

Comment:

 Tom Boothby, I'm adding you to the CC since this also fixes the problem
 with the tracebacks you mentioned to me last January.

 This version of the patch is hopefully the final version of the patch. It
 does the following:

 * Uses ast to replace the displayhook_hack in `sagenb.misc.format`, this
 was achieved through the efforts of me and Alex Leone (thank you!).

  * The new version, now named `parse_display_expr`, can now print either
 the last expression, as before:

 {{{
 1
 2
 3
 ----
 3
 }}}

   or all root level expressions:

 {{{
 1
 2
 for x in range(3):
     x
 3
 -----
 1
 2
 3
 }}}

   or all expressions:

 {{{
 1
 2
 for x in range(2):
     x
 3
 -----
 1
 2
 0
 1
 3
 }}}

      This new functionality is customizable via the Notebook Settings
 page.

 * Adds new WorksheetProcess implementations based on `multiprocessing`,
 and deprecates the pexpect based ones, since this also changes the
 WorksheetProcess API. The blocking reference implementation has been
 updated to the new API.

  * The local implementation (`WorksheetProcess_PipesImpl`) is on average
 251.3 ms faster than the pexpect based one.

  * The remote implementation ('WorksheetProcess_RemoteSSHPipesImpl`) is on
 average 212 ms faster than the remote pexpect based one. For now, it has
 the same vulnerabilities as the old one, with one additional: the
 connection between the main server and the computing server is
 unencrypted, and thus may be snooped on. It is trivial to fix this,
 however I am not sure whether the speed (and extra computing load)
 tradeoffs are worth it.

 * It now formats tracebacks as:

 {{{
 Traceback (most recent call last):
   Line 7, in <module>
     bar()
   Line 5, in bar
     foo()
   Line 2, in foo
     raise Exception("Hello")
 Exception: Hello
 }}}

 instead of:

 {{{
 Traceback (most recent call last):    def baz():
   File "", line 1, in <module>

   File "/tmp/tmpfzcGzr/___code___.py", line 13, in <module>
     baz()
   File "", line 1, in <module>

   File "/tmp/tmpfzcGzr/___code___.py", line 10, in baz
     bar()
   File "/tmp/tmpfzcGzr/___code___.py", line 7, in bar
     foo()
   File "/tmp/tmpfzcGzr/___code___.py", line 4, in foo
     raise Exception("Hello")
 Exception: Hello
 }}}

 which have their line numbers offset by +2, also.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7997#comment:10>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to