当前位置: 首页>>代码示例>>Python>>正文


Python socket.getdefaulttimeout方法代码示例

本文整理汇总了Python中socket.getdefaulttimeout方法的典型用法代码示例。如果您正苦于以下问题:Python socket.getdefaulttimeout方法的具体用法?Python socket.getdefaulttimeout怎么用?Python socket.getdefaulttimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socket的用法示例。


在下文中一共展示了socket.getdefaulttimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: downloadAndShow

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def downloadAndShow(self):
        """Triggered when the user wants to download and see the file"""
        url = self.selectedText.strip()
        if url.lower().startswith("www."):
            url = "http://" + url

        oldTimeout = socket.getdefaulttimeout()
        newTimeout = 5      # Otherwise the pause is too long
        socket.setdefaulttimeout(newTimeout)
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

        try:
            response = urllib.request.urlopen(url)
            content = decodeURLContent(response.read())

            # The content has been read sucessfully
            mainWindow = GlobalData().mainWindow
            mainWindow.editorsManager().newTabClicked(content,
                                                      os.path.basename(url))
        except Exception as exc:
            logging.error("Error downloading '" + url + "'\n" + str(exc))

        QApplication.restoreOverrideCursor()
        socket.setdefaulttimeout(oldTimeout) 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:26,代码来源:qpartwrap.py

示例2: test_timeout

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
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)

#
# Test what happens with no "if __name__ == '__main__'"
# 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_multiprocessing.py

示例3: test_tls_error_ftp

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def test_tls_error_ftp(self):
        s = None
        try:
            def_timeout = socket.getdefaulttimeout()
            socket.setdefaulttimeout(5)
            s = make_socket_server(8021, lambda s, d: s.send(b'220 Welcome to FooFTP\n'))
            with assert_exception(self, errors.TLSError, 'remote end closed the connection|server responded using FTP'):
                tls.TLSSocket('localhost', 8021)
        finally:
            if s:
                s.close()
            socket.setdefaulttimeout(def_timeout) 
开发者ID:wbond,项目名称:oscrypto,代码行数:14,代码来源:test_tls.py

示例4: socket_timeout

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def socket_timeout(seconds=15):
    cto = socket.getdefaulttimeout()
    try:
        socket.setdefaulttimeout(seconds)
        yield
    finally:
        socket.setdefaulttimeout(cto) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:util.py

示例5: socket_timeout

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def socket_timeout(timeout=15):
    def _socket_timeout(func):
        def _socket_timeout(*args, **kwargs):
            old_timeout = socket.getdefaulttimeout()
            socket.setdefaulttimeout(timeout)
            try:
                return func(*args, **kwargs)
            finally:
                socket.setdefaulttimeout(old_timeout)
        return _socket_timeout
    return _socket_timeout 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:package_index.py

示例6: _new_fixed_fetch

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def _new_fixed_fetch(validate_certificate):
        def fixed_fetch(url, payload=None, method="GET", headers={},
                        allow_truncated=False, follow_redirects=True,
                        deadline=None):
            if deadline is None:
                deadline = socket.getdefaulttimeout() or 5
            return fetch(url, payload=payload, method=method, headers=headers,
                         allow_truncated=allow_truncated,
                         follow_redirects=follow_redirects, deadline=deadline,
                         validate_certificate=validate_certificate)
        return fixed_fetch 
开发者ID:mortcanty,项目名称:earthengine,代码行数:13,代码来源:__init__.py

示例7: socket_timeout

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def socket_timeout(timeout=15):
    def _socket_timeout(func):
        def _socket_timeout(*args, **kwargs):
            old_timeout = socket.getdefaulttimeout()
            socket.setdefaulttimeout(timeout)
            try:
                return func(*args, **kwargs)
            finally:
                socket.setdefaulttimeout(old_timeout)

        return _socket_timeout

    return _socket_timeout 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:15,代码来源:package_index.py

示例8: testDefaultTimeout

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def testDefaultTimeout(self):
        # Testing default timeout
        # The default timeout should initially be None
        self.assertEqual(socket.getdefaulttimeout(), None)
        s = socket.socket()
        self.assertEqual(s.gettimeout(), None)
        s.close()

        # Set the default timeout to 10, and see if it propagates
        socket.setdefaulttimeout(10)
        self.assertEqual(socket.getdefaulttimeout(), 10)
        s = socket.socket()
        self.assertEqual(s.gettimeout(), 10)
        s.close()

        # Reset the default timeout to None, and see if it propagates
        socket.setdefaulttimeout(None)
        self.assertEqual(socket.getdefaulttimeout(), None)
        s = socket.socket()
        self.assertEqual(s.gettimeout(), None)
        s.close()

        # Check that setting it to an invalid value raises ValueError
        self.assertRaises(ValueError, socket.setdefaulttimeout, -1)

        # Check that setting it to an invalid type raises TypeError
        self.assertRaises(TypeError, socket.setdefaulttimeout, "spam") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_socket.py

示例9: _testTimeoutDefault

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def _testTimeoutDefault(self):
        # passing no explicit timeout uses socket's global default
        self.assertTrue(socket.getdefaulttimeout() is None)
        socket.setdefaulttimeout(42)
        try:
            self.cli = socket.create_connection((HOST, self.port))
            self.addCleanup(self.cli.close)
        finally:
            socket.setdefaulttimeout(None)
        self.assertEqual(self.cli.gettimeout(), 42) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_socket.py

示例10: _testTimeoutNone

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def _testTimeoutNone(self):
        # None timeout means the same as sock.settimeout(None)
        self.assertTrue(socket.getdefaulttimeout() is None)
        socket.setdefaulttimeout(30)
        try:
            self.cli = socket.create_connection((HOST, self.port), timeout=None)
            self.addCleanup(self.cli.close)
        finally:
            socket.setdefaulttimeout(None)
        self.assertEqual(self.cli.gettimeout(), None) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_socket.py

示例11: testTimeoutDefault

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def testTimeoutDefault(self):
        # default -- use global socket timeout
        self.assertIsNone(socket.getdefaulttimeout())
        socket.setdefaulttimeout(30)
        try:
            ftp = ftplib.FTP(HOST)
        finally:
            socket.setdefaulttimeout(None)
        self.assertEqual(ftp.sock.gettimeout(), 30)
        self.evt.wait()
        ftp.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_ftplib.py

示例12: testTimeoutNone

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def testTimeoutNone(self):
        # no timeout -- do not use global socket timeout
        self.assertIsNone(socket.getdefaulttimeout())
        socket.setdefaulttimeout(30)
        try:
            ftp = ftplib.FTP(HOST, timeout=None)
        finally:
            socket.setdefaulttimeout(None)
        self.assertIsNone(ftp.sock.gettimeout())
        self.evt.wait()
        ftp.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_ftplib.py

示例13: testTimeoutNone

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def testTimeoutNone(self):
        self.assertIsNone(socket.getdefaulttimeout())
        socket.setdefaulttimeout(30)
        try:
            smtp = smtplib.SMTP(HOST, self.port, timeout=None)
        finally:
            socket.setdefaulttimeout(None)
        self.assertIsNone(smtp.sock.gettimeout())
        smtp.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_smtplib.py

示例14: test_http_basic

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def test_http_basic(self):
        self.assertIsNone(socket.getdefaulttimeout())
        url = test_support.TEST_HTTP_URL
        with test_support.transient_internet(url, timeout=None):
            u = _urlopen_with_retry(url)
            self.assertIsNone(u.fp._sock.fp._sock.gettimeout()) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_urllib2net.py

示例15: test_http_default_timeout

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getdefaulttimeout [as 别名]
def test_http_default_timeout(self):
        self.assertIsNone(socket.getdefaulttimeout())
        url = test_support.TEST_HTTP_URL
        with test_support.transient_internet(url):
            socket.setdefaulttimeout(60)
            try:
                u = _urlopen_with_retry(url)
            finally:
                socket.setdefaulttimeout(None)
            self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 60) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_urllib2net.py


注:本文中的socket.getdefaulttimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。