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()