MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['urllib3.util (D:\\Python\\venv\\lib\\site-packages\\urllib3\\util\\__init__.py)', 'urllib3.util.ssl_ (D:\\Python\\venv\\lib\\site-packages\\urllib3\\util\\ssl_.py)']. monkey.patch_all()
时间: 2023-07-12 16:05:43 浏览: 200
这是一条警告信息,意思是在 ssl 模块被导入后再进行 Monkey Patch 可能会导致错误,特别是在 Python 3.6 上可能会出现递归错误(RecursionError),在 Python 3.7 上还可能导致不正确的行为。建议在导入 ssl 模块之前进行 Monkey Patch。同时,这条信息还列出了那些已经被直接导入的模块,这些模块不应该被 Monkey Patch。最后,代码中调用了 monkey.patch_all() 方法,这个方法会自动对一些常用模块进行 Monkey Patch。
相关问题
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Related to AboutOpenClasses in the Ruby Koans # from runner.koan import * class AboutMonkeyPatching(Koan): class Dog: def bark(self): return "WOOF" def test_as_defined_dogs_do_bark(self): fido = self.Dog() self.assertEqual('WOOF', fido.bark()) # ------------------------------------------------------------------ # Add a new method to an existing class. def test_after_patching_dogs_can_both_wag_and_bark(self): def wag(self): return "HAPPY" self.Dog.wag = wag fido = self.Dog() self.assertEqual('HAPPY', fido.wag()) self.assertEqual('WOOF', fido.bark()) # ------------------------------------------------------------------ def test_most_built_in_classes_cannot_be_monkey_patched(self): try: int.is_even = lambda self: (self % 2) == 0 except Exception as ex: err_msg = ex.args[0] self.assertRegex(err_msg, "can't set attributes of built-in") # ------------------------------------------------------------------ class MyInt(int): pass def test_subclasses_of_built_in_classes_can_be_be_monkey_patched(self): self.MyInt.is_even = lambda self: (self % 2) == 0 self.assertEqual(False, self.MyInt(1).is_even()) self.assertEqual(True, self.MyInt(2).is_even())
这段代码是一个 Python 的单元测试,测试了 Monkey Patching 的一些特性。Monkey Patching 是指在运行时动态修改类或对象的行为。在这段代码中,定义了一个 Dog 类,其中有一个 bark 方法。然后通过 Monkey Patching 的方式给 Dog 类添加了一个新的方法 wag。接着展示了一个不能被 Monkey Patching 的内置类型 int,以及一个继承自 int 的自定义类 MyInt,展示了后者可以进行 Monkey Patching。最后通过几个测试用例来验证 Monkey Patching 的效果。其中包括:
- 测试原本定义的 Dog 类是否能够正常运作。
- 测试 Monkey Patching 后 Dog 类是否能够正常运作。
- 测试不能被 Monkey Patching 的内置类型 int。
- 测试继承自内置类型 int 的自定义类 MyInt 是否可以进行 Monkey Patching,并验证 Monkey Patching 的效果。
make: Leaving directory '/home/wanglangtao/frifly/rk3399_linux_release_v2.5.1_20210301/buildroot' 2023-06-07T03:54:43 >>> host-gcc-initial 8.4.0 Building 2023-06-07T03:54:47 >>> host-gcc-initial 8.4.0 Installing to host directory 2023-06-07T03:54:49 >>> host-libtool 2.4.6 Extracting 2023-06-07T03:54:50 >>> host-libtool 2.4.6 Patching 2023-06-07T03:54:50 >>> host-libtool 2.4.6 Updating config.sub and config.guess 2023-06-07T03:54:50 >>> host-libtool 2.4.6 Configuring 2023-06-07T03:54:53 >>> host-libtool 2.4.6 Building 2023-06-07T03:54:54 >>> host-libtool 2.4.6 Installing to host directory 2023-06-07T03:54:55 >>> host-autoconf 2.69 Extracting 2023-06-07T03:54:55 >>> host-autoconf 2.69 Patching 2023-06-07T03:54:55 >>> host-autoconf 2.69 Updating config.sub and config.guess 2023-06-07T03:54:55 >>> host-autoconf 2.69 Patching libtool 2023-06-07T03:54:55 >>> host-autoconf 2.69 Configuring 2023-06-07T03:54:56 >>> host-autoconf 2.69 Building 2023-06-07T03:54:57 >>> host-autoconf 2.69 Installing to host directory 2023-06-07T03:54:57 >>> host-automake 1.15.1 Extracting 2023-06-07T03:54:57 >>> host-automake 1.15.1 Patching 2023-06-07T03:54:57 >>> host-automake 1.15.1 Updating config.sub and config.guess 2023-06-07T03:54:57 >>> host-automake 1.15.1 Patching libtool 2023-06-07T03:54:58 >>> host-automake 1.15.1 Configuring 2023-06-07T03:54:59 >>> host-automake 1.15.1 Building 2023-06-07T03:54:59 >>> host-automake 1.15.1 Installing to host directory 2023-06-07T03:55:00 >>> host-pkgconf 0.9.12 Extracting 2023-06-07T03:55:00 >>> host-pkgconf 0.9.12 Patching 2023-06-07T03:55:00 >>> host-pkgconf 0.9.12 Updating config.sub and config.guess 2023-06-07T03:55:00 >>> host-pkgconf 0.9.12 Patching libtool 2023-06-07T03:55:00 >>> host-pkgconf 0.9.12 Configuring 2023-06-07T03:55:00 >>> host-pkgconf 0.9.12 Building 2023-06-07T03:55:01 >>> host-pkgconf 0.9.12 Installing to host directory 2023-06-07T03:55:02 >>> host-libxml2 2.9.7 Extracting 2023-06-07T03:55:02 >>> host-libxml2 2.9.7 Patching 2023-06-07T03:55:02 >>> host-libxml2 2.9.7 Updating config.sub and config.guess 2023-06-07T03:55:02 >>> host-libxml2 2.9.7 Patching libtool 2023-06-07T03:55:02 >>> host-libxml2 2.9.7 Configuring 2023-06-07T03:55:06 >>> host-libxml2 2.9.7 Building 2023-06-07T03:55:22 >>> host-libxml2 2.9.7 Installing to host directory 2023-06-07T03:55:24 >>> host-gettext 0.19.8.1 Extracting 2023-06-07T03:55:25 >>> host-gettext 0.19.8.1 Patching 2023-06-07T03:55:26 >>> host-gettext 0.19.8.1 Updating config.sub and config.guess 2023-06-07T03:55:26 >>> host-gettext 0.19.8.1 Configuring 2023-06-07T03:55:26 >>> host-gettext 0.19.8.1 Autoreconfiguring 2023-06-07T03:55:51 >>> host-gettext 0.19.8.1 Patching libtool 2023-06-07T03:56:13 >>> host-gettext 0.19.8.1 Building什么问题
这并不是一个问题,而是一段命令行输出。这段输出是在进行一个名为"rk3399_linux_release_v2.5.1_20210301"的项目构建过程中产生的。其中包括了使用不同的工具和库进行编译、安装等操作,如host-gcc-initial、host-libtool、host-autoconf、host-automake、host-pkgconf、host-libxml2、host-gettext等。这些命令的具体含义需要结合项目的具体情况来分析。
阅读全文