开发者

compiled python library works on one computer but not on another

I have written a python interface to c++ code.I have two different computers running ubuntu 11.04 with the same packages (python 2.7.1, numpy 1.5.1, gcc 4.5.2). Let's call them A and B.

The code compiles and links without errors on both computers. However, on A, the code seems to enter an infinite loop somewhere in the middle of the c++ code (The CPU is working, but the program never ends). If I copy this very same shared library to computer B, it works without any problems.

I can reproduce this with small changes to the code, different parameters etc. I have used valgrind, but there are no memory leaks / accesses to memory that was not allocated before etc. The code does not depend on anything but libraries开发者_开发知识库 installed by the package management system, so these are identical.

Does anyone have any plausible explanation where this might come from? Other than the following (that I have checked):

  • A and B run the same libraries/packages of everything
  • The underlying c++ library has no outside dependencies except for boost::function and STL
  • Everything is cleanly compiled from scratch using the same build system/compiler
  • environment variables are the same


Which compiler was used to build python on your machine ? This is a crucial point for Python extensions. If you use a different compiler anything bad can happen.


Even if you are not multithreading (as in defining multiple threads) there may be a SMP problem: if a memory location is volatile, context switches and CPU scheduling may cause the program to 'not' see the actual changes.

  • Did you try to compile without any optimizations (-O0 on gcc).
  • Are there any variables that could be volatile and ought to be marked as such (think of device inputs, zero copy buffers, mmaps).

Even if you're not (explicitely) doing any threading, I'd not be surprised if Python's garbage collection runs on a separate thread anyway.


Different computers might have different processors/architecture. Ideally, you would compile Python on the other computer as well. Do this and you'll know if the problem was copying the libraries over, or if it's something on your code, or if it's an environment configuration thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜