Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Can't thread with permutation groups?

I'm having trouble running threads involving permutation groups. Here is a small example that shows the issue on Sage 5.2 (and also Sage 4.8).

import time
from threading import Thread

class f(Thread):
    def __init__(self,val):
        Thread.__init__(self)
        self.val=val
    def run(self):
        G=CyclicPermutationGroup(self.val)
        print 'here'
        print G

a=f(4)
b=f(4)
a.start()
b.start()
a.join()
b.join()

The "here"s print but then the worksheet (usually) just keeps running without doing anything and refuses to be interrupted, or (sometimes) crashes and offers error messages such as

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/sagenb/sage_install/sage-5.2-sage.math.washington.edu-x86_64-Linux/local/lib/python/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/tmp/tmp4JA7Av/___code___.py", line 14, in run
    print G
  File "sage_object.pyx", line 154, in sage.structure.sage_object.SageObject.__repr__ (sage/structure/sage_object.c:1753)
  File "/sagenb/sage_install/sage-5.2-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/groups/perm_gps/permgroup_named.py", line 436, in _repr_
    return "Cyclic group of order %s as a permutation group"%self.order()
  File "/sagenb/sage_install/sage-5.2-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/groups/perm_gps/permgroup.py", line 1400, in order
    if not self.gens() or self.gens() == [self(1)]:
  File "/sagenb/sage_install/sage-5.2-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/groups/perm_gps/permgroup.py", line 646, in __call__
    return self.identity()
  File "/sagenb/sage_install/sage-5.2-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/groups/perm_gps/permgroup.py", line 902, in identity
    return self._element_class()([], self, check=True)
  File "permgroup_element.pyx", line 452, in sage.groups.perm_gps.permgroup_element.PermutationGroupElement.__init__ (sage/groups/perm_gps permgroup_element.c:4337)
  File "sage_object.pyx", line 463, in sage.structure.sage_object.SageObject._gap_ (sage/structure/sage_object.c:4518)
  File "sage_object.pyx", line 439, in sage.structure.sage_object.SageObject._interface_ (sage/structure/sage_object.c:4118)
  File "/sagenb/sage_install/sage-5.2-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/interfaces/interface.py", line 198, in __call__
    return cls(self, x, name=name)
  File "/sagenb/sage_install/sage-5.2-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/interfaces/expect.py", line 1328, in __init__
    raise TypeError, x
TypeError: Gap produced error output
Syntax error: ; expected
$sage2:=Group([PermList([2, 3, 4, 1])]);;
 ^

   executing $sage2:=Group([PermList([2, 3, 4, 1])]);;

I've gotten other error messages as well, but nothing I can reliably reproduce.

If you delete the start and join lines for a or b in the code, it runs fine, of course.

Any ideas here? In case you're curious, the reason I'm trying to thread is this. I have a bunch of problems that can be solved by either of two different methods. For any given problem, one method is usually much faster than the other, but it's difficult to predict in advance which one will be the faster one, so for a given problem I'd like to run both methods simultaneously and accept the result from whichever method finishes first. Any ideas for how to do this in a way that avoids this error are welcome.