当前位置:首页>python>【一起学 Python】第 64 天:上下文管理器 with 语句的深度解析

【一起学 Python】第 64 天:上下文管理器 with 语句的深度解析

  • 2026-04-24 00:37:22
【一起学 Python】第 64 天:上下文管理器 with 语句的深度解析

欢迎来到 Python 学习计划的第 64 天!🎉

昨天我们学习了 文件写入与编码问题,掌握了如何安全地保存数据。今天,我们将深入理解 Python 中最优雅的语法之一——with 语句(上下文管理器)

这是 异常与文件模块的最后一天。掌握 with 的底层原理,你不仅能正确使用它,还能创建自己的上下文管理器,让资源管理更加自动化和安全!

一、什么是上下文管理器?

1. 定义

上下文管理器(Context Manager) 是实现了 __enter__ 和 __exit__ 方法的对象,用于管理资源的获取和释放。

2. 为什么需要它?

在 [File 90](90-else 与 finally 的执行时机.md) 中我们学习了 finally 用于资源清理,但每次都写 try-finally 很繁琐。with 语句将这一模式封装起来,让代码更简洁。

# ❌ 繁琐的 try-finallyf = open("data.txt""r")try:    content = f.read()finally:    f.close()# ✅ 优雅的 with 语句with open("data.txt""r"as f:    content = f.read()# 自动关闭文件,即使发生异常

3. 核心优势

  • 自动资源管理:无需手动关闭文件、连接等。
  • 异常安全:即使块内发生异常,资源也会被正确释放。
  • 代码简洁:减少样板代码,提高可读性。

二、with 语句的底层原理

1. 执行流程

with 语句的执行过程等价于以下代码:

# with 语句with expression as variable:    block# 等价于manager = expressionvariable = manager.__enter__()try:    blockfinally:    manager.__exit__(*sys.exc_info())

2. 两个核心方法

方法

调用时机

返回值

作用

__enter__

进入 with 块时

返回给 as 后的变量

获取资源

__exit__

离开 with 块时

None 或 False 传播异常

释放资源

3. 手动实现等价代码

class FileManager:    def __init__(self, filename, mode):        self.filename = filename        self.mode = mode        self.file = None    def __enter__(self):        print("进入 with 块")        self.file = open(self.filename, self.mode)        return self.file  # 返回给 as 后的变量    def __exit__(self, exc_type, exc_val, exc_tb):        print("离开 with 块")        if self.file:            self.file.close()        # 返回 None 或 False,异常会继续传播        return False# 使用with FileManager("data.txt""r"as f:    content = f.read()

三、exit 方法详解

1. 参数说明

__exit__ 接收三个参数,用于处理异常信息:

def __exit__(self, exc_type, exc_val, exc_tb):    """    exc_type: 异常类型(如 ValueError)    exc_val:  异常值(如错误信息)    exc_tb:   异常堆栈跟踪对象    """    if exc_type:        print(f"发生异常:{exc_type.__name__}{exc_val}")    # 返回 True 抑制异常,返回 False 或 None 让异常继续传播

2. 异常抑制

如果 __exit__ 返回 True,异常会被抑制,不会向上传播。

class SuppressError:    def __enter__(self):        return self    def __exit__(self, exc_type, exc_val, exc_tb):        print("捕获并抑制异常")        return True  # 抑制异常with SuppressError():    raise ValueError("这个异常不会传播")print("程序继续执行")  # 会执行

3. 记录异常信息

可以在 __exit__ 中记录异常日志,然后让异常继续传播。

import loggingclass LogErrors:    def __enter__(self):        return self    def __exit__(self, exc_type, exc_val, exc_tb):        if exc_type:            logging.error(f"{exc_type.__name__}{exc_val}")        return False  # 让异常继续传播with LogErrors():    raise ValueError("记录日志后继续传播")

四、contextlib 模块(简化实现)

Python 提供了 contextlib 模块,可以用更简单的方式创建上下文管理器。

1. @contextmanager 装饰器

使用生成器函数代替类实现。

from contextlib import contextmanager@contextmanagerdef open_file(filename, mode):    f = open(filename, mode)    try:        yield f  # yield 前的代码是 __enter__,之后是 __exit__    finally:        f.close()# 使用with open_file("data.txt""r"as f:    content = f.read()

2. 带异常处理的生成器

from contextlib import contextmanager@contextmanagerdef transaction(db):    db.begin()    try:        yield db        db.commit()    except Exception:        db.rollback()        raise  # 重新抛出异常# 使用with transaction(database) as db:    db.execute("INSERT INTO users ...")

3. closing() 工具

为有 close() 方法的对象快速创建上下文管理器。

from contextlib import closingimport urllib.requestwith closing(urllib.request.urlopen("http://example.com")) as response:    content = response.read()

4. suppress() 工具

抑制特定异常,等价于前面的 SuppressError

from contextlib import suppresswith suppress(FileNotFoundError):    os.remove("不存在的文件.txt")# 不会抛出异常# 等价于try:    os.remove("不存在的文件.txt")except FileNotFoundError:    pass

五、OOP 实战应用

1. 数据库连接管理器

from typing import Optionalfrom contextlib import contextmanagerclass DatabaseConnection:    """数据库连接上下文管理器"""    def __init__(self, host: str, port: int, database: str):        self.host = host        self.port = port        self.database = database        self.connection = None    def __enter__(self):        print(f"连接到 {self.host}:{self.port}/{self.database}")        # 模拟连接        self.connection = {"host"self.host, "connected"True}        return self.connection    def __exit__(self, exc_type, exc_val, exc_tb):        print("关闭数据库连接")        if self.connection:            self.connection["connected"] = False        # 返回 False,让异常继续传播        return False    def execute(self, sql: str):        if not self.connection or not self.connection["connected"]:            raise RuntimeError("数据库未连接")        print(f"执行 SQL: {sql}")        return []# 使用with DatabaseConnection("localhost"3306"mydb"as db:    db.execute("SELECT * FROM users")# 输出:# 连接到 localhost:3306/mydb# 执行 SQL: SELECT * FROM users# 关闭数据库连接

2. 计时器上下文管理器

import timefrom contextlib import contextmanager@contextmanagerdef timer(name: str = "操作"):    """计时上下文管理器"""    start = time.time()    try:        yield    finally:        elapsed = time.time() - start        print(f"{name} 耗时:{elapsed:.4f}秒")# 使用with timer("数据处理"):    time.sleep(1)    result = sum(range(1000000))with timer("文件读取"):    with open("data.txt""w"as f:        f.write("test")

3. 临时目录管理器

import osimport shutilfrom pathlib import Pathfrom contextlib import contextmanager@contextmanagerdef temporary_directory(path: str):    """创建临时目录,退出时自动删除"""    dir_path = Path(path)    dir_path.mkdir(parents=True, exist_ok=True)    print(f"创建临时目录:{dir_path}")    try:        yield dir_path    finally:        print(f"删除临时目录:{dir_path}")        shutil.rmtree(dir_path, ignore_errors=True)# 使用with temporary_directory("temp/data"as tmp_dir:    # 在临时目录中操作    (tmp_dir / "file.txt").write_text("内容")    print(f"临时文件:{tmp_dir / 'file.txt'}")# 退出后目录自动删除

六、常见误区与注意事项

1. exit 返回值的影响

# 返回 True:抑制异常class SuppressAll:    def __exit__(self, *args):        return Truewith SuppressAll():    raise ValueError("不会传播")print("继续执行")  # 会执行# 返回 False/None:传播异常class PropagateError:    def __exit__(self, *args):        return Falsewith PropagateError():    raise ValueError("会传播")print("不会执行")  # 不会执行

2. 嵌套 with 语句

可以嵌套多个 with 语句,Python 3.10+ 支持括号写法。

# 传统写法with open("input.txt"as f_in:    with open("output.txt""w"as f_out:        f_out.write(f_in.read())# Python 3.10+ 括号写法with (    open("input.txt"as f_in,    open("output.txt""w"as f_out):    f_out.write(f_in.read())

3. 不要在 exit 中抛出异常

如果 __exit__ 中抛出异常,会覆盖 with 块中的原始异常。

class BadExit:    def __exit__(self, *args):        raise RuntimeError("清理时出错")with BadExit():    raise ValueError("原始错误")# 最终只看到 RuntimeError,原始错误丢失

4. yield 只能使用一次

使用 @contextmanager 时,生成器只能 yield 一次。

# ❌ 错误@contextmanagerdef bad_context():    setup()    yield    yield  # 第二次 yield 会报错    cleanup()# ✅ 正确@contextmanagerdef good_context():    setup()    try:        yield    finally:        cleanup()

七、总结

知识点

说明

上下文管理器

实现 __enter__ 和 __exit__ 的对象

enter

进入 with 块时调用,返回资源

exit

离开 with 块时调用,清理资源

@contextmanager

用生成器简化上下文管理器实现

suppress()

抑制特定异常

closing()

为有 close() 方法的对象创建上下文

异常传播

__exit__ 返回 True 抑制,False 传播

核心要点

  1. with 自动管理资源,无需手动 close()
  2. __exit__ 接收异常信息,可选择是否抑制。
  3. @contextmanager 简化实现,用 yield 分隔进入和退出逻辑。
  4. 嵌套 with 支持多资源管理,Python 3.10+ 支持括号语法。
  5. 不要在 __exit__ 中抛出异常,会覆盖原始错误。

🎉 模块总结:异常与文件(第 57-64 天)

📌 明日预告:为什么需要类型提示?

恭喜!你已完成 异常与文件模块(第 57-64 天)

明天我们将回顾并进入 类型提示模块的复习与综合实战

  • 主题:类型提示与异常处理综合实战
  • 核心问题
    1. 如何为文件操作函数添加类型提示?
    2. 如何设计带异常处理的类型安全 API?
    3. 上下文管理器的类型如何标注?
    4. 综合项目:实现类型安全的配置管理器

💡 提前思考

  1. with open(...) as f: 中 f 的类型是什么?
  2. 如何用类型提示表示函数可能抛出异常?
  3. 如何将今天学的上下文管理器与类型提示结合?

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-04-25 05:21:45 HTTP/2.0 GET : https://f.mffb.com.cn/a/486520.html
  2. 运行时间 : 0.124235s [ 吞吐率:8.05req/s ] 内存消耗:4,494.20kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=44ca24dab2af9f12b8127c77fe9ab623
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000540s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.001097s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000365s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000331s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000657s ]
  6. SELECT * FROM `set` [ RunTime:0.000266s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000782s ]
  8. SELECT * FROM `article` WHERE `id` = 486520 LIMIT 1 [ RunTime:0.000669s ]
  9. UPDATE `article` SET `lasttime` = 1777065705 WHERE `id` = 486520 [ RunTime:0.001081s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000281s ]
  11. SELECT * FROM `article` WHERE `id` < 486520 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000627s ]
  12. SELECT * FROM `article` WHERE `id` > 486520 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.001093s ]
  13. SELECT * FROM `article` WHERE `id` < 486520 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.003140s ]
  14. SELECT * FROM `article` WHERE `id` < 486520 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.005421s ]
  15. SELECT * FROM `article` WHERE `id` < 486520 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.001872s ]
0.125907s