abstract:python 2.7.11,下载链接 https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz,如下载速度太慢可在豆瓣pypi搜索下载 https://pypi.doubanio.com/simple/python升级到2.7.11可解决 内置的 socket库的setdefaulttimeout
python 2.7.11,下载链接 https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz,如下载速度太慢可在豆瓣pypi搜索下载 https://pypi.doubanio.com/simple/
python升级到2.7.11可解决 内置的 socket库的setdefaulttimeout方法和multiprocessing库的manage队列冲突的问题,在2.7.3版本是需要改源码才能解决。问题如下
Traceback (most recent call last): File "/usr/local/lib/python2.7/multiprocessing/process.py", line 232, in _bootstrap self.run() File "/usr/local/lib/python2.7/multiprocessing/process.py", line 88, in run self._target(*self._args, **self._kwargs) File "agentInstaller.py", line 445, in getInstallInfo lock.acquire() File "/usr/local/lib/python2.7/multiprocessing/managers.py", line 960, in acquire return self._callmethod('acquire', (blocking,)) File "/usr/local/lib/python2.7/multiprocessing/managers.py", line 729, in _callmethod self._connect() File "/usr/local/lib/python2.7/multiprocessing/managers.py", line 716, in _connect conn = self._Client(self._token.address, authkey=self._authkey) File "/usr/local/lib/python2.7/multiprocessing/connection.py", line 149, in Client answer_challenge(c, authkey) File "/usr/local/lib/python2.7/multiprocessing/connection.py", line 383, in answer_challenge message = connection.recv_bytes(256) # reject large message IOError: [Errno 11] Resource temporarily unavailable
解决问题可以修改源代码文件 /usr/local/lib/python2.7/multiprocessing/connection.py
def Pipe(duplex=True): ''' Returns pair of connection objects at either end of a pipe ''' if duplex: s1, s2 = socket.socketpair() s1.setblocking(True) s2.setblocking(True) c1 = _multiprocessing.Connection(os.dup(s1.fileno())) c2 = _multiprocessing.Connection(os.dup(s2.fileno())) s1.close() s2.close() else: fd1, fd2 = os.pipe() c1 = _multiprocessing.Connection(fd1, writable=False) c2 = _multiprocessing.Connection(fd2, readable=False) return c1, c2 def __init__(self, address, family, backlog=1): self._socket = socket.socket(getattr(socket, family)) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._socket.setblocking(True) self._socket.bind(address) self._socket.listen(backlog) self._address = self._socket.getsockname() self._family = family self._last_accepted = None def accept(self): s, self._last_accepted = self._socket.accept() s.setblocking(True) fd = duplicate(s.fileno()) conn = _multiprocessing.Connection(fd) s.close() return conn def SocketClient(address): ''' Return a connection object connected to the socket given by `address` ''' family = address_type(address) s = socket.socket( getattr(socket, family) ) s.setblocking(True) t = _init_timeout()
修改 /usr/local/lib/python2.7/test/test_multiprocessing.py
assert sio.getvalue() == 'foo' # Test interaction with socket timeouts - see Issue #6056 # class TestTimeouts(unittest.TestCase): @classmethod def _test_timeout(cls, child, address): time.sleep(1) child.send(123) child.close() conn = multiprocessing.connection.Client(address) conn.send(456) conn.close() def test_timeout(self): old_timeout = socket.getdefaulttimeout() try: socket.setdefaulttimeout(0.1) parent, child = multiprocessing.Pipe(duplex=True) l = multiprocessing.connection.Listener(family='AF_INET') p = multiprocessing.Process(target=self._test_timeout, args=(child, l.address)) p.start() child.close() self.assertEqual(parent.recv(), 123) parent.close() conn = l.accept() self.assertEqual(conn.recv(), 456) conn.close() l.close() p.join(10) finally: socket.setdefaulttimeout(old_timeout) testcases_other = [OtherTest, TestInvalidHandle, TestInitializers, #- TestStdinBadfiledescriptor] TestStdinBadfiledescriptor, TestTimeouts]
升级2.7.11的其他好处就去看官网描述吧。安装过程如下:
curl -k https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz -o python-2.7.11.tgz yum -y install gcc gcc-c++ autoconf yum -y install ncurses ncurses-devel yum -y install mysql-devel tar xf Python-2.7.11.tgz cd Python-2.7.11/ ./configure make -j4 && make install
升级完重新打开secureCRT窗口
[root@master ~]# python Python 2.7.11 (default, Nov 4 2016, 14:13:05) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2 Type "help", "copyright", "credits" or "license" for more information.>>>
安装readline
yum -y install readline-devel yum -y install patch yum -y install gcc python-devel zlib-devel openssl-devel libffi-devel easy_install readline
安装MySQLdb
tar zxf MySQL-python-1.2.3.tar.gz cd MySQL-python-1.2.3 python setup.py build python setup.py install
如果出现下面问题
>>> import MySQLdb /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.pyc, but /home/opd/tmpFiles/singleExec/MySQL-python-1.2.3 is being added to sys.path Traceback (most recent call last): File "<stdin>", line 1, in <module> File "MySQLdb/__init__.py", line 19, in <module> import _mysql File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in <module> File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__ ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory >>>
解决方法如下
# 根据最后提示,应该是找不着一个交libmysqlclient.so.18的文件,于是到mysql安装目录里找到这个文件并且做一个软连接到/usr/lib ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20 # 如果是64系统则: ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20