Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Porting Python "Numeric"



Hi Folks,

I've tried this question on the macpython, python and fink lists. I'm sure there must be some way to sort out what's going on, but I can't seem to track it down. Anyway... I thought I'd give it a go here. The problem seems to crop up when one thread (in this case a thread trying to display an image based on a "Numeric" array) causes errno to be set in another thread. How can this happen? The threads are using a "thread lock" object to keep from stepping on eachothers' toes.

thanks,
-steve

From: Steve Spicklemire <email@hidden>
Date: Wed Feb 27, 2002  07:28:37 AM America/Indianapolis
To: email@hidden
Cc: email@hidden
Subject: errno, threads, Numeric etc...  how to debug this?


Hi Folks,

I'm trying to build Numeric on MacOSX and while it basically works... it seems there are some problems. When I try to run the Demos/NumTut examples (using xfree86 and python2.2 from fink) I get random "unexpected math error" exceptions.

I checked the source and discovered that the errors are occuring in ufuncmodule. I edited ufuncmodule to get more info like so:

[spicklemire:~/Packages] steve% diff -c Numeric-20.3-orig/Src/ufuncobject.c Numeric-20.3/Src/ufuncobject.c
*** Numeric-20.3-orig/Src/ufuncobject.c Tue Aug 14 11:18:24 2001
--- Numeric-20.3/Src/ufuncobject.c Mon Feb 25 15:42:08 2002
***************
*** 470,477 ****
if (self->check_return) check_array(mps[i]);
}


!     if (self->check_return && errno != 0) {math_error(); return -1;}
!
      return 0;
  }

--- 470,488 ----
        if (self->check_return) check_array(mps[i]);
      }

!     if (self->check_return && (errno != 0))
!       {
!       if ((errno == EDOM) || (errno == ERANGE))
!         {
!           math_error(); return -1;
!         }
!       else
!         {
!           fprintf(stderr, "Hmm.. error encountered -> %i\n", errno);
!           perror("error in ufunc generic function:");
!         }
!       }
!
      return 0;
  }


Now when I try to run the NumTut demo I see:

[spicklemire:~/Packages/Numeric-20.3/Demo] steve% python -c "import NumTut;NumTut.test()"
>>> view(greece)
>>> view(1.0-greece)
Hmm.. error encountered -> 35
error in ufunc generic function:: Resource temporarily unavailable
>>> view(greeceBW)
>>> view(greece*xgrade)
>>> view(greece*ygrade)
>>> negative = 1.0 - greece
>>> view(greece*xgrade + negative*ygrade)
>>> view(red)
>>> view(green)
>>> view(blue)
>>> sine = sin(xgrade*6*pi)
>>> view(green*sine + red*(1.0-sine))
>>> view(green + red[::-1])
>>> view(transpose(greece, (1,0,2)))
[spicklemire:~/Packages/Numeric-20.3/Demo] steve% python -c "import NumTut;NumTut.test()"
>>> view(greece)
>>> view(1.0-greece)
>>> view(greeceBW)
>>> view(greece*xgrade)
>>> view(greece*ygrade)
>>> negative = 1.0 - greece
>>> view(greece*xgrade + negative*ygrade)
>>> view(red)
>>> view(green)
>>> view(blue)
>>> sine = sin(xgrade*6*pi)
>>> view(green*sine + red*(1.0-sine))
>>> view(green + red[::-1])
>>> view(transpose(greece, (1,0,2)))
[spicklemire:~/Packages/Numeric-20.3/Demo] steve% python -c "import NumTut;NumTut.test()"
>>> view(greece)
>>> view(1.0-greece)
Hmm.. error encountered -> 35
error in ufunc generic function:: Resource temporarily unavailable
>>> view(greeceBW)
>>> view(greece*xgrade)
>>> view(greece*ygrade)
>>> negative = 1.0 - greece
>>> view(greece*xgrade + negative*ygrade)
>>> view(red)
>>> view(green)
>>> view(blue)
>>> sine = sin(xgrade*6*pi)
>>> view(green*sine + red*(1.0-sine))
>>> view(green + red[::-1])
>>> view(transpose(greece, (1,0,2)))


So... ufuncs just multiply, divide and suchlike! What "resources" are not available? It's fairly clear that it's thread related, since all the Numeric tests pass every time in a non-threaded example, as well as my own non-threaded testing to attempt to reproduce what I thought originally was a linking problem.

So... how can I track down where errno is actually getting set? Does the fact that it happens "randomly" mean that it's not due to some numerical computation, but more likely about timing between threads?

Also.. it seems that on MacOSX there is a separate "errno" value for each thread... so how could they be confused?

thanks for any insight. ;-)

-steve
_______________________________________________
unix-porting mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/unix-porting
Do not post admin requests to the list. They will be ignored.



References: 
 >Re: what defines do I look for? (From: "Peter O'Gorman" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.