Python 报错 Fatal Python error: PyFrame_BlockPop: block stack underflow 如何解决?

在使用PyCharm的调试模式运行Python代码时遇到一个致命错误:`Fatal Python error: PyFrame_BlockPop: block stack underflow`。该错误仅在调试时出现,正常运行则不会。错误详细信息显示了涉及的Python库和线程信息。代码中包含一个原神抽卡模拟器的实现,但具体代码内容并未导致问题。解决方案可能涉及到检查调试配置或代码中的异常处理部分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Fatal Python error: PyFrame_BlockPop: block stack underflow

只有使用pycharm的debug时会报错,正常run就不会


完整报错内容:

Fatal Python error: PyFrame_BlockPop: block stack underflow
Python runtime state: initialized

Thread 0x000040a8 (most recent call first):
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\threading.py", line 324 in wait
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\threading.py", line 600 in wait
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\pydevd.py", line 150 in _on_run
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 219 in run
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009 in _bootstrap_inner
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\threading.py", line 966 in _bootstrap

Thread 0x00003e74 (most recent call first):
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 293 in _on_run
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 219 in run
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009 in _bootstrap_inner
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\threading.py", line 966 in _bootstrap

Thread 0x00002fe0 (most recent call first):
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\threading.py", line 324 in wait
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\queue.py", line 180 in get
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 368 in _on_run
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 219 in run
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009 in _bootstrap_inner
  File "C:\Users\***\AppData\Local\Programs\Python\Python310\lib\threading.py", line 966 in _bootstrap

Current thread 0x00001b38 (most recent call first):
  File "D:/pythonProject/random projects/Genshin simulator.py", line 73 in <module>
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18 in execfile
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1491 in _exec
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1484 in run
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\pydevd.py", line 2172 in main
  File "D:\PyCharm Community Edition 2022.1.2\plugins\python-ce\helpers\pydev\pydevd.py", line 2181 in <module>

Extension modules: _pydevd_bundle.pydevd_cython_win32_310_64, _pydevd_bundle.pydevd_cython, _pydevd_frame_eval.pydevd_frame_evaluator_common, _pydevd_frame_eval.pydevd_frame_evaluator_win32_310_64, numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, matplotlib._c_internal_utils, PIL._imaging, matplotlib._path, kiwisolver, matplotlib._image, matplotlib.backends._tkagg (total: 23)

Process finished with exit code -1073740791 (0xC0000409)


代码:

代码内容应该不是很重要,就是随便写的一个原神抽卡模拟器,作为一个新手写的应该也挺差的

文件链接:Genshin simulator

import numpy as np
import random
import matplotlib.pyplot as plt
import collections


class ResultType:
    def __init__(self, cumsum_start=0, base_probability=0., max_rel_place=0, name=None):
        self.last = 0
        self.places = {}
        self.rel_place = 0
        self.cumsum_start = cumsum_start
        self.base_probability = base_probability
        self.max_rel_place = max_rel_place
        self.name = name


def cnt_add(dic, value):
    if value in dic.keys():
        dic[value] += 1
    else:
        dic[value] = 1
    return dic


def draw(*probs):
    cum_weights = standardize_cum_weights(probs) + [1]
    out = random.choices(['g', 'p', 'b'], cum_weights=cum_weights)[0]
    if out == 'g':
        if last_gold_up:
            specific_out = random.choices(['n', 'u'])[0]
        else:
            specific_out = 'u'
    elif out == 'p':
        specific_out = random.choices(['n', 'u', 'w'],
                                      weights=[1 / 4, 1 / 4, 1 / 2])[0]
    else:
        specific_out = 'w'
    return out, specific_out


def standardize_cum_weights(cum_weights):
    cum_weights = list(cum_weights)
    # noinspection PyShadowingNames
    for i in range(1, len(cum_weights)):
        if cum_weights[i] < cum_weights[i - 1]:
            cum_weights[i] = cum_weights[i - 1]
    return cum_weights


gold = ResultType(cumsum_start=70, base_probability=0.006, max_rel_place=90, name='gold')
purple = ResultType(cumsum_start=5, base_probability=0.051, max_rel_place=10, name='purple')

times = int(input())
last_gold_up = True

results = np.empty((times, 2), dtype=str)

for i in range(1, times + 1):

    try:
        for res in (gold, purple):
            res.rel_place += 1
            if res.rel_place <= res.cumsum_start:
                res.probability = res.base_probability
            else:
                res.probability = (1 - res.base_probability) / sum(range(res.max_rel_place - res.cumsum_start)) * (
                        res.rel_place - res.cumsum_start) + res.probability
        if purple.rel_place == 11:
            raise ValueError
    except ValueError:
        print(gold.probability, purple.probability)
        pass

    result = draw(gold.probability, purple.probability)

    if result[0] == 'g':
        gold.places = cnt_add(gold.places, gold.rel_place)
        gold.rel_place = 0
    elif result[0] == 'p':
        purple.places = cnt_add(purple.places, purple.rel_place)
        purple.rel_place = 0

    results[i - 1] = result

plt.figure(figsize=(12, 7))

i = 1

for res in (gold, purple):
    x = list(range(1, res.max_rel_place + 1))
    y = np.zeros(res.max_rel_place)
    y[np.array(list(res.places.keys())) - 1] = list(res.places.values())
    plt.subplot(1, 2, i)
    plt.bar(x, y, color=res.name)
    i += 1

plt.show()
### 增加 Node.js 内存限制 在 Vue 项目构建过程中,如果遇到 `FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory` 错误,通常是因为 Node.js 默认的内存限制不足以处理当前项目的打包需求。可以通过调整 Node.js 的内存限制来解决这个问题,使用 `--max-old-space-size` 参数可以增加 V8 引擎的老生代内存池大小。例如,将内存限制增加到 4096MB: ```bash node --max-old-space-size=4096 your_script.js ``` 对于 Vue CLI 项目,可以在 `package.json` 的启动脚本中直接添加该参数以应用于构建过程: ```json "scripts": { "build": "node --max-old-space-size=4096 node_modules/@vue/cli-service/bin/vue-cli-service.js build" } ``` 此外,也可以修改 `.bin` 目录下的 `webpack-dev-server.cmd` 文件,在其中添加 `--max-old-space-size=4096` 参数以扩展内存限制[^2]。 ### 优化构建流程与依赖管理 除了提升内存限制外,还可以通过优化代码结构和依赖管理来减少内存消耗。大型项目应尽量避免冗余依赖,并采用更高效的模块加载方式。例如,使用 Webpack 的 **Code Splitting** 功能将代码拆分为多个块,按需加载,从而降低单次构建时的内存压力。同时,合理使用 **懒加载**(Lazy Loading)机制也有助于减少初始构建时的资源占用[^3]。 ### 检查并修复潜在的内存泄漏 内存不足的问题也可能源于程序内部的内存泄漏。可以借助 Chrome DevTools、Node.js 自带的调试工具或第三方分析工具(如 `heapdump` 和 `node-inspector`)来检测内存使用情况。通过生成堆快照(Heap Snapshot),可识别出哪些对象占用了过多内存,并据此优化代码逻辑。 ### 升级开发环境版本 确保使用的 Vue CLI 和 Node.js 版本为最新稳定版,因为新版本通常包含性能优化和内存管理方面的改进。例如,Vue CLI 4.3.1 及以上版本已经对大型项目有更好的支持[^1]。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值