Ask Your Question

Is there a command like Mathematica's Dynamic[] in Sage?

asked 2016-09-27 22:34:44 -0500

barrybr gravatar image

updated 2016-09-27 22:37:01 -0500

I'm on a Mac with OS 10.11.6 and I'm using Sage 7.2's notebook interface. I did things in Mathematica that I want to check in Sage, but I'm a beginner at Sage. In Mathematica it's possible to keep track of the execution of my code, especially to detect when it's hanging, by using the Mathematica Dynamic[] command. Is there anything like this command in Sage, or is there perhaps another way to track the progress of the execution of a lengthy computation that will let me know in real time if and when it hangs? At the moment I insert print commands in my code that result in thousands of tuples of values of a tuple of variables streaming vertically down my screen. Messy. I'd rather see the values of such a tuple simply update in place as they do, say, on a digital clock. (This is what Dynamic[] achieves in Mathematica.)

edit retag flag offensive close merge delete


There is a "profiling" section in the tutorial which could be helpful.

Mafra gravatar imageMafra ( 2016-09-30 06:17:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-10-01 13:08:04 -0500

tmonteil gravatar image

updated 2016-10-01 14:47:24 -0500

Sage in written in Python, so you can benefit of any good things from it. Searching a couple of seconds on the web led me to the following:

sage: from time import sleep
sage: from sys import stdout
sage: for i in range(10):
....:     stdout.write("\rDoing thing %i" % i)
....:     stdout.flush()
....:     sleep(1)

There might even be dedicated libraries.

edit flag offensive delete link more


This is fine for the command line, but not effective in the notebook. Output on stdout is appended to the cell rather than replacing its contents.

paulmasson gravatar imagepaulmasson ( 2016-10-01 14:49:33 -0500 )edit

Hmm, indeed. It works in the jupyter notebook however.

tmonteil gravatar imagetmonteil ( 2016-10-01 15:43:02 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2016-09-27 22:34:44 -0500

Seen: 133 times

Last updated: Oct 01 '16