Hi,
I played around a little during the sage status reports seminar today
with importing the sage library in a second *thread*, which was
something that Robert Bradshaw suggested. This has potential. I'm
recording something about this here, just for the record (it doesn't
really fit for a trac ticket).
(1) I created this b.py file
from threading import Thread
class Imp(Thread):
def run(self):
import time; t = time.time()
print "Background importing sage.all..."
import sage.all
print "Done!, time=%s"%(time.time()-t)
(2) I wrapped all signal calls in the sage library in try/except:
blocks (there were 3 such places; see attached patch).
(3) Then I did:
wst...@ubuntu:~/tmp$ sage -ipython
...
In [1]: import b; b.Imp().start()
Background importing sage.all...
In [2]: print 2+7
------> print(2+7)
9
In [3]: Done!, time=7.73341584206
In [4]: import sage.all # takes *no* time
-- William
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
--
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
diff -r 41a16cd736e4 sage/all.py
--- a/sage/all.py Fri Feb 26 07:28:26 2010 -0800
+++ b/sage/all.py Fri Mar 05 17:04:32 2010 -0800
@@ -59,7 +59,10 @@
import sage.ext.sig
sage.ext.sig.get_bad_sigs()
from sage.interfaces.get_sigs import get_sigs
-get_sigs()
+try:
+ get_sigs()
+except: pass
+
from sage.misc.all import * # takes a while
diff -r 41a16cd736e4 sage/interfaces/all.py
--- a/sage/interfaces/all.py Fri Feb 26 07:28:26 2010 -0800
+++ b/sage/interfaces/all.py Fri Mar 05 17:04:32 2010 -0800
@@ -35,7 +35,11 @@
from r import r, r_console, R, r_version, is_RElement
# signal handling
-from get_sigs import *
+try:
+ from get_sigs import *
+except Exception, msg:
+ print msg
+
interfaces = ['gap', 'gp', 'mathematica', 'gnuplot', \
'kash', 'magma', 'macaulay2', 'maple', 'maxima', \
diff -r 41a16cd736e4 sage/interfaces/get_sigs.py
--- a/sage/interfaces/get_sigs.py Fri Feb 26 07:28:26 2010 -0800
+++ b/sage/interfaces/get_sigs.py Fri Mar 05 17:04:32 2010 -0800
@@ -12,9 +12,10 @@
raise RuntimeError, "A floating point exception occurred."
def get_sigs():
- signal.signal(signal.SIGINT, my_sigint)
- signal.signal(signal.SIGABRT, my_sigint)
- signal.signal(signal.SIGFPE, my_sigfpe)
- signal.signal(signal.SIGALRM, my_sigint)
+ try:
+ signal.signal(signal.SIGINT, my_sigint)
+ signal.signal(signal.SIGABRT, my_sigint)
+ signal.signal(signal.SIGFPE, my_sigfpe)
+ signal.signal(signal.SIGALRM, my_sigint)
+ except: pass
-
diff -r 41a16cd736e4 sage/libs/pari/gen.pyx
--- a/sage/libs/pari/gen.pyx Fri Feb 26 07:28:26 2010 -0800
+++ b/sage/libs/pari/gen.pyx Fri Mar 05 17:04:32 2010 -0800
@@ -7974,15 +7974,18 @@
GP_DATA.fmt.sigd = prec_bits_to_dec(53)
# Take control of SIGSEGV back from PARI.
- import signal
- signal.signal(signal.SIGSEGV, signal.SIG_DFL)
-
- # We do the following, since otherwise the IPython pager
- # causes sage to crash when it is exited early. This is
- # because when PARI was initialized it set a trap for this
- # signal.
- import signal
- signal.signal(signal.SIGPIPE, _my_sigpipe)
+ try:
+ import signal
+ signal.signal(signal.SIGSEGV, signal.SIG_DFL)
+
+ # We do the following, since otherwise the IPython pager
+ # causes sage to crash when it is exited early. This is
+ # because when PARI was initialized it set a trap for this
+ # signal.
+ import signal
+ signal.signal(signal.SIGPIPE, _my_sigpipe)
+ except:
+ pass
initialized = 1
stack_avma = avma
num_primes = maxprime