Extension/Threading conflict under Win2k

Keith Farmer kfarmer at thuban.org
Mon Jan 28 20:24:37 EST 2002


I'm trying to track this down do either a bug in 2.1.x, or in my
C-extension.  This one's stumped me, and the folks at Zope don't know what's
going on, either.

Here's a copy of my submission to the sourceforge bug tracker:

https://sourceforge.net/tracker/?func=detail&aid=508700&group_id=5470&atid=1
05470

PythonWin 2.1 (#15, Apr 16 2001, 18:25:49)
Running on Win2k SP2 (both Pro and Server)

Source code for the extension is at http://www.thuban.org/projects (see
AstroMath). (Zip file uploaded)

As suggested, I set up a couple threading/non-threading tests outside of
Zope. Here are the results, and the sourcecode for the scripts. My guess now
is that it's a Python error, or something that I don't know about how
C-extensions behave under Python threads.

AstroMathTest.py -- threaded, import outside of the thread run() method
AstroMathTest-2.py -- threaded, import inside the thread run() method
AstroMathTest-3.py -- unthreaded, import outside of the class

AstroMathTest.py triggers an abnormal termination (when running under Zope,
this crashes the server). The others execute normally.

.....

Here are the two threaded test scripts.  The first will crash:

# AstroMathTest.py
#
# Tests AstroMath against Python threads

import threading
import AstroMath
import random

BODIES = [2,3,4,6,7,8,9,10]
START_JD = 2448976
N = 1000

class AstroMathTest(threading.Thread):
    def run(self):
        body = random.choice(BODIES)
        end_jd = random.randrange(START_JD + 1, START_JD + 100)
        results = AstroMath.makeQVsop(START_JD, end_jd, N, body)
        print "Period: %s - %s\nBody: %s\nN: %s" % (START_JD, end_jd, body,
N)
        print "Results: %s" % str(results)

if __name__ == '__main__':
    threads = []
    for i in range(3):
        thread = AstroMathTest()
        thread.start()
        threads.append(thread)
    # wait for completion
    for thread in threads:
        thread.join()
    print "All threads completed"


... whereas this will run successfully:

# AstroMathTest-2.py
#
# Tests AstroMath against Python threads

import threading
import random

BODIES = [2,3,4,6,7,8,9,10]
START_JD = 2448976
N = 1000

class AstroMathTest(threading.Thread):
    def run(self):
        import AstroMath
        body = random.choice(BODIES)
        end_jd = random.randrange(START_JD + 1, START_JD + 100)
        results = AstroMath.makeQVsop(START_JD, end_jd, N, body)
        print "Period: %s - %s\nBody: %s\nN: %s" % (START_JD, end_jd, body,
N)
        print "Results: %s" % str(results)

if __name__ == '__main__':
    threads = []
    for i in range(3):
        thread = AstroMathTest()
        thread.start()
        threads.append(thread)
    # wait for completion
    for thread in threads:
        thread.join()
    print "All threads completed"

.....

The source code for the dll, as mentioned, is at
http://www.thuban.org/projects/AstroMath/astromath.cpp

----------
Keith J. Farmer
kfarmer at thuban.org
http://www.thuban.org





More information about the Python-list mailing list