我试图从源代码编译Python 2.7.
这是我的命令:
./configure --prefix=/my/local/dir --exec-prefix=/my/local/dir --enable-shared --with-pydebug
make
make install
Run Code Online (Sandbox Code Playgroud)
而输出which python是/my/local/dir/bin/python,这是正确的.
但是当我跑步时,python --version我看到了Python 2.7.3而不是Python 2.7.10.
Python的系统版本是2.7.3.可能是Python的系统版本以某种方式将自己与本地编译版本链接起来?或者我做错了什么?
编辑:
输出./my/local/dir/bin/python --version也是Python 2.7.3
编辑2:
似乎如果我摆脱--enable-shared它将产生正确版本的Python的标志,但我需要该标志让我的其他软件工作.
我有一个python函数,如果传递坏数据会被无限循环捕获.我想写一个单元测试来确认它优雅地处理坏参数.问题当然是,如果它没有检测到错误的参数,它将不会返回.
使用线程为这类事物编写测试是否可以接受?
import threading, unittest
import mymodule
class CallSuspectFunctionThread(threading.Thread):
def __init__(self, func, *args):
self.func = func
self.args = args
super(CallSuspectFunctionThread, self).__init__()
def run(self):
self.func(*self.args)
class TestNoInfiniteLoop(unittest.TestCase):
def test_no_infinite_loop(self):
myobj = mymodule.MyObject()
bad_args = (-1,0)
test_thread = CallSuspectFunctionThread(mybj.func_to_test, *bad_args)
test_thread.daemon = True
test_thread.start()
# fail if func doesn't return after 8 seconds
for i in range(32):
test_thread.join(0.25)
if not test_thread.is_alive():
return
self.fail("function doesn't return")
Run Code Online (Sandbox Code Playgroud)
我看到的唯一问题是,如果测试失败,我会遇到这个额外的线程,可能会消耗cpu和内存资源,而其余的测试都会被执行.另一方面,我已经修复了代码,回归的可能性非常小,所以我不知道是否包括测试是否重要.