Web services Jython CGIHTTPServer错误“套接字必须处于非阻塞模式”

Web services Jython CGIHTTPServer错误“套接字必须处于非阻塞模式”,web-services,sockets,jython,blocking,Web Services,Sockets,Jython,Blocking,通过“jython-m CGIHTTPServer”将jython用作CGI服务器会导致C-Python中不存在的错误:错误:20000,“套接字必须处于非阻塞模式” 如果像我这样的人想使用jython作为jython模型、脚本等的简单CGI服务器,这是不可接受的。我找到了解决办法,希望这也能帮助其他人: 编辑文件jython/Lib/select.py并转到标记行,添加两行箭头,如下所示。然后,所有这些都可以正常工作,正如C-Python所知 jython/Lib/select.py: ...

通过“jython-m CGIHTTPServer”将jython用作CGI服务器会导致C-Python中不存在的错误:错误:20000,“套接字必须处于非阻塞模式”

如果像我这样的人想使用jython作为jython模型、脚本等的简单CGI服务器,这是不可接受的。我找到了解决办法,希望这也能帮助其他人:

编辑文件jython/Lib/select.py并转到标记行,添加两行箭头,如下所示。然后,所有这些都可以正常工作,正如C-Python所知

jython/Lib/select.py:

... 

class poll:

... 

  def register(self, socket_object, mask = POLLIN|POLLOUT|POLLPRI):
      try:            

          try:    socket_object.setblocking(0)  # <-- line to add
          except: pass                          # <-- line to add

          channel = _getselectable(socket_object)
          if channel is None:
              # The socket is not yet connected, and thus has no channel
              # Add it to a pending list, and return
              self.unconnected_sockets.append( (socket_object, mask) )
              return
          self._register_channel(socket_object, channel, mask)
      except java.lang.Exception, jlx:
          raise _map_exception(jlx)

  ...

在一些应用程序中,我在响应过程中遇到了setblocking0问题。因此,我还修改了jython/Lib/socket.py,如下所示:

jython/Lib/socket.py:

class _tcpsocket(_nonblocking_api_mixin): 

  ...

  def send(self, s):
      try:
          if not self.sock_impl: raise error(errno.ENOTCONN, 'Socket is not connected')
          if self.sock_impl.jchannel.isConnectionPending():
            self.sock_impl.jchannel.finishConnect()
          numwritten = self.sock_impl.write(s)            

          # try again in blocking mode
          if numwritten == 0 and self.mode == MODE_NONBLOCKING: # <-- line to add
            try:    self.setblocking(1)                         # <-- line to add
            except: pass                                        # <-- line to add
            numwritten = self.sock_impl.write(s)                # <-- line to add


          if numwritten == 0 and self.mode == MODE_NONBLOCKING:
              raise would_block_error()
          return numwritten
      except java.lang.Exception, jlx:
          raise _map_exception(jlx)

  ...   
我知道这两个更改都不是很“干净”,但这是让Jython作为CGIHTTPServer像Python一样工作的唯一方法