python升级到2.7.11可解决 内置的
socket库的setdefaulttimeout方法和multiprocessing库的manage队列冲突的问题,在2.7.3版本是需要改源码才能解决。python
2.7.11,下载链接点击这里。问题如下

在启用HTTPS过程中,在生成CSR(证书请求文件)时,报错了,说Python2.6已被Python团队抛弃了,所以升级Python到2.7。

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

步骤1:下载python2.7.12

157    def Pipe(duplex=True):
158        ”’
159        Returns pair of connection objects at either end of a pipe
160        ”’
161        if duplex:
162            s1, s2 = socket.socketpair()
++163          s1.setblocking(True)                                     
                                                                       
                                         
++164          s2.setblocking(True)
165            c1 = _multiprocessing.Connection(os.dup(s1.fileno()))
166            c2 = _multiprocessing.Connection(os.dup(s2.fileno()))
167            s1.close()
168            s2.close()
169        else:
170            fd1, fd2 = os.pipe()
171            c1 = _multiprocessing.Connection(fd1, writable=False)
172            c2 = _multiprocessing.Connection(fd2, readable=False)
173
174        return c1, c2

  wget 

226    def __init__(self, address, family, backlog=1):
227        self._socket = socket.socket(getattr(socket, family))
228        self._socket.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR, 1)
++229      self._socket.setblocking(True)                             
                                                                       
                                           
230        self._socket.bind(address)
231        self._socket.listen(backlog)
232        self._address = self._socket.getsockname()
233        self._family = family
234        self._last_accepted = None

步骤2:解压

243    def accept(self):
244        s, self._last_accepted = self._socket.accept()
++245      s.setblocking(True)                                         
                                                                       
                                         
246        fd = duplicate(s.fileno())
247        conn = _multiprocessing.Connection(fd)
248        s.close()
249        return conn

  tar -zxvf Python-2.7.12.tgz

257 def SocketClient(address):
258    ”’
259    Return a connection object connected to the socket given by
`address`
260    ”’
261    family = address_type(address)
262    s = socket.socket( getattr(socket, family) )
++263  s.setblocking(True)                                             
                                                                       
                                         
264    t = _init_timeout()

步骤3:切换工作目录

修改 /usr/local/lib/python2.7/test/test_multiprocessing.py

  cd Python-2.7.12

 assert sio.getvalue() == ‘foo’
2029
++2030 # Test interaction with socket timeouts – see Issue #6056
++ 2031 #
++ 2032
++ 2033 class TestTimeouts(unittest.TestCase):
++ 2034    @classmethod
++ 2035    def _test_timeout(cls, child, address):
++ 2036        time.sleep(1)
++ 2037        child.send(123)
++ 2038        child.close()
++ 2039        conn = multiprocessing.connection.Client(address)
++ 2040        conn.send(456)
++ 2041        conn.close()
++ 2042
++ 2043    def test_timeout(self):
++ 2044        old_timeout = socket.getdefaulttimeout()
++ 2045        try:
++ 2046            socket.setdefaulttimeout(0.1)
++ 2047            parent, child = multiprocessing.Pipe(duplex=True)
++ 2048            l =
multiprocessing.connection.Listener(family=’AF_INET’)
++ 2049            p =
multiprocessing.Process(target=self._test_timeout,
++ 2050                                        args=(child,
l.address))
++ 2051            p.start()
++ 2052            child.close()
++ 2053            self.assertEqual(parent.recv(), 123)
++ 2054            parent.close()
++ 2055            conn = l.accept()
++ 2056            self.assertEqual(conn.recv(), 456)
++ 2057            conn.close()
++ 2058            l.close()
++ 2059            p.join(10)
++ 2060        finally:
++ 2061            socket.setdefaulttimeout(old_timeout)
++ 2062
++ 2063
++ 2064 testcases_other = [OtherTest, TestInvalidHandle,
TestInitializers,
–2065 #-                  TestStdinBadfiledescriptor]
++ 2066                  TestStdinBadfiledescriptor, TestTimeouts]

步骤4:创建python2.7目录

升级2.7.11的其他好处就去看官网描述吧。安装过程如下:

  mkdir /usr/local/python2.7

curl -k -o
python-2.7.11.tgz

步骤5:安装

yum -y install gcc gcc-c++ autoconf

  (1) ./configure –prefix=/usr/local/python2.7 (–prefix表示安装的路径,一定指明)

yum -y install ncurses ncurses-devel

  (2) make

yum -y install mysql-devel

  (3) make install

tar xf Python-2.7.11.tgz
cd Python-2.7.11/
./configure
make -j4 && make install

  (4) make clean  删除由make命令产生的文件

升级完重新打开secureCRT窗口

  (5) make distclean删除由./configure产生的文件

[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.
>>>

步骤6:建立软连接,使系统默认的 python指向 python2.7.12

安装readline

  (1) mv /usr/bin/python  /usr/bin/python_2.6.6 这一步很重要,相当于备用,步骤7会用到的

Author

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章