The problem with refcount of python object
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- python
调研方向
运行提供的 Python 脚本,并记录 get_object.cache_clear() 前后的 refcount、cache_info 输出以及 TestObj 销毁消息。然后检查 lru_cache、ThreadPoolExecutor 和 FluentHandler 之间的交互,以确定预期的所有权行为,并定义可复现的修复方案或结果文档。
由索引模型根据 Issue 内容生成。
描述
1. from functools import lru_cache
2. import fluent.handler
3. import logging
4. import logging.config
5. import sys
6. from concurrent.futures import ThreadPoolExecutor
7.
8. logging.basicConfig(level=logging.INFO)
9.
10. fluentd_format = {
11. 'hostname': '%(hostname)s',
12. 'module': '%(module)s.%(funcName)s',
13. 'where': '%(filename)s:%(lineno)d',
14. 'level': '%(levelname)s',
15. 'exception': '%(exc_text)s',
16. 'process': '%(processName)s',
17. }
18.
19.
20. def fluentd_handler(pendings):
21. if fluentd_handler.first_time:
22. fluentd_handler.first_time = False
23. print("failed to send log to fluentd")
24.
25.
26. fluentd_handler.first_time = True
27.
28. def setup_fluent(tag, host, port):
29. root = logging.getLogger()
30. fluent_handler = fluent.handler.FluentHandler(tag, host=host, port=port,
31. buffer_overflow_handler=fluentd_handler,
32. nanosecond_precision=True)
33. fluent_handler.setLevel(logging.INFO)
34. formatter = fluent.handler.FluentRecordFormatter(fluentd_format)
35. fluent_handler.setFormatter(formatter)
36. root.addHandler(fluent_handler)
37.
38. class TestObj(object):
39. def __init__(self, name, idx):
40. self.name = name
41. self.idx = idx
42.
43. def __del__(self):
44. print("test obj destroyed!")
45.
46. def doing(self):
47. print('name:%s,idx:%s' % (self.name, self.idx))
48.
49.
50. @lru_cache(maxsize=64)
51. def get_object(name , id):
52. return TestObj(name, id);
53.
54.
55. def cache_test():
56. obj1 = get_object('segment000', 0)
57. logging.info("TestObj's refcount is %s", sys.getrefcount(obj1))
58.
59. if __name__ == '__main__':
60. setup_fluent('cachetest', 'localhost', 24224)
61. pool = ThreadPoolExecutor(max_workers=2)
62. for i in range(20):
63. f = pool.submit(cache_test)
64. f.result()
65. logging.info('before clearing,cache info:%s', get_object.cache_info())
66. get_object.cache_clear()
67. logging.info('after clearing,cache info:%s', get_object.cache_info())
- 主要语言
- Python
- 星标
- 457
- 派生
- 138
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fluent/fluent-logger-python 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 48/100
fluent/fluent-logger-python#210 ·
-
难度 3/5 1-2 天 新手友好度 25/100
fluent/fluent-logger-python#196 ·
-
难度 3/5 1-2 天 新手友好度 42/100
fluent/fluent-logger-python#195 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 45/100
fluent/fluent-logger-python#194 ·
-
难度 3/5 1-2 天 新手友好度 48/100
fluent/fluent-logger-python#190 ·
查看 fluent/fluent-logger-python 的全部 Issue
相似的 Issue
-
documentation help wanted
难度 2/5 1-3 小时 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 90/100
simonw/sqlite-utils#872 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 78/100