Ask Your Question

Keep Sage running in background linux

asked 2017-06-22 20:37:19 +0200

Andriy gravatar image

updated 2017-06-22 21:34:40 +0200

I need to be able to execute sage commands via the command line without opening the Sage shell. I am currently doing this through "sage -c 'cmd'". The issue I have is that this forces all of sage to boot up, run the command, and then shutdown. Something simple as "sage -c "print(derivative(5*x,x))" takes 3-4 seconds to run. How would I speed this up? My idea was to somehow run Sage in the background and be able to feed it input but I am not sure how to do that. I am feeding the command line input from an external program.

EDIT: I found something that may be useful here: (

The solution this user provides is creating a python socket server to constantly be running sage and pass along input for evaluation into it. The code isn't exactly daemonized so I will attempt to do that later. I will report on if I got it to work.

edit retag flag offensive close merge delete



Having such a daemon for Sage would be very nice. Do not hesitate to share your code when it is working !

tmonteil gravatar imagetmonteil ( 2017-06-23 10:52:14 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-09-29 12:21:08 +0200

Harald Schilly gravatar image

You can solve this by running sage as a webservice. E.g. a simply way is to install flask and instantiate a server, then code an endpoint and send the input there. As long as these commands are stateless, you can even use setup a simple WSGI app and use gunicorn to spawn several sage instances on the backend.

edit flag offensive delete link more

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: 2017-06-22 20:37:19 +0200

Seen: 1,495 times

Last updated: Sep 29 '17