Ask Your Question
1

Keep Sage running in background linux

asked 2017-06-22 13:37:19 -0600

Andriy gravatar image

updated 2017-06-22 14:34:40 -0600

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: https://ask.sagemath.org/question/23431/running-sage-from-other-languages-with-higher-performance/ (https://ask.sagemath.org/question/234...)

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

Comments

2

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 03:52:14 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-09-29 05:21:08 -0600

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

Stats

Asked: 2017-06-22 13:37:19 -0600

Seen: 79 times

Last updated: Sep 29