ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 29 Sep 2017 12:21:08 +0200Keep Sage running in background linuxhttps://ask.sagemath.org/question/38057/keep-sage-running-in-background-linux/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/
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.Thu, 22 Jun 2017 20:37:19 +0200https://ask.sagemath.org/question/38057/keep-sage-running-in-background-linux/Comment by tmonteil for <p>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.</p>
<p>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...)</p>
<p>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.</p>
https://ask.sagemath.org/question/38057/keep-sage-running-in-background-linux/?comment=38065#post-id-38065Having such a daemon for Sage would be very nice. Do not hesitate to share your code when it is working !Fri, 23 Jun 2017 10:52:14 +0200https://ask.sagemath.org/question/38057/keep-sage-running-in-background-linux/?comment=38065#post-id-38065Answer by schilly for <p>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.</p>
<p>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...)</p>
<p>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.</p>
https://ask.sagemath.org/question/38057/keep-sage-running-in-background-linux/?answer=39000#post-id-39000You 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. Fri, 29 Sep 2017 12:21:08 +0200https://ask.sagemath.org/question/38057/keep-sage-running-in-background-linux/?answer=39000#post-id-39000