港真,这个问题整的我快抑郁了,排雷花了三四天时间,网上说啥的都有。先说结论吧,最终的解决方案是把代码里用到的pandas库降低了版本,用的1.1.5版本,才没再次报该错误。教训就是:即使是python库,也尽量不要用最新版,因为不知道哪里会产生奇奇怪怪的bug!用新版本后面的比较稳定的老版本,起码非常稳定!

接下来细说。

事情是这样,客户要求给他写个脚本,然后因为请求量大,所以用threading多线程搞比较好一些,一次性开10000个线程+ip随机切换,起码不会被封本地ip。接下来先上部分代码。

import codecs
import csv
import os
import random
import sha3
import ecdsa
from web3 import Web3
import threading
import time
import smtplib
from email.header import Header
from email.mime.text import MIMEText
import pandas as pd
import requests
from bs4 import BeautifulSoup

# 从该网站不定时抓取可用ip地址,并单独作为一个线程使用
def getip():
    try:
        for i in range(1, 10):
            if len(list(set(ip_url_list))) < 3000:
                url = 'https://www.kuaidaili.com/free/inha/' + str(i) + '/'
                headers = {}
                re = requests.get(url, headers=headers)
                soup = BeautifulSoup(re.text, 'html.parser')
                ip_datas = soup.find('table')
                df_tables = pd.read_html(str(ip_datas))
                for j in range(len(df_tables)):
                    df = df_tables[j]
                    df_ip_list = df['IP'].tolist()
                    df_port_list = df['PORT'].tolist()
                    df_http_type = df['类型'].tolist()
                    if len(df_ip_list) == len(df_port_list):
                        for i in range(len(df_ip_list)):
                            ip_url = df_http_type[i].lower() + '://' + str(df_ip_list[i]) + ':' + str(df_port_list[i])
                            ip_url_list.append(ip_url)
                print('ip_url_list:{} \n ip_url_list列表长度:{} '.format(list(set(ip_url_list)),len(list(set(ip_url_list)))))
                # df_ips = pd.DataFrame(list(set(ip_url_list)))       # 列表去重
                # df_ips.to_csv('IP代理地址.csv', encoding='utf-8', index=False)
                time.sleep(random.randint(60, 120))
    except BaseException:
        pass

# 核心代码不放了,因为与最终的报错无关,需要全部代码请私信哈

if __name__ == "__main__":

    # 启动IP代理线程
    ip_thread = threading.Thread(target=getip)
    ip_thread.start()

    # 私钥碰撞线程表
    threads = []
    for i in range(10000):
        thread = threading.Thread(target=hit_key)
        threads.append(thread)
    for t in range(len(threads)):
        threads[t].start()
        # threads[t].join(10)        # 保证内存稳定
        # threads.remove(threads[t])    # 保证内存稳定

起初,当产生这个报错的时候,我谷歌了一下,结果是说啥的都有,全部试了一遍,都没一点用处。只能放弃。————放弃一次😂

后来我注意到报错信息里有这么一条:

_PyEval_EvalFrameDefault returned a result with an error set

谷歌了一下发现一样说啥的都有,而且解决方案很少,全网找不到可用的解决方案。只能放弃。————放弃两次😂

紧接着我又仔细阅读了报错信息,发现一个Unable set什么的错误,但把多线程加到10000后,这个错误很常见————放弃三次😂

然后我把windows电脑的.py文件拷贝到mac电脑,发现代码能正常运行,一切正常,这就基本说明了是windows电脑配置、环境或者pycharm库的问题。

为了避免是多线程库带来的问题,我把if下面的所有代码注释掉,使用while 1循环来处理,看看不用threading会不会报错,结果发现如果不用多线程,在windows上运行一切正常。

if __name__ == "__main__":
    """
    # 启动IP代理线程
    ip_thread = threading.Thread(target=getip)
    ip_thread.start()

    # 私钥碰撞线程表
    threads = []
    for i in range(10000):
        thread = threading.Thread(target=hit_key)
        threads.append(thread)
    for t in range(len(threads)):
        threads[t].start()
        # threads[t].join(10)        # 保证内存稳定,防止线程内存增加
        # threads.remove(threads[t])    # 保证内存稳定,防止线程内存增加
    """
    while 1:
    	hitkey()

这就奇怪了,这说明在windows上,threading这个库可能和其他库冲突了,因为不用threading的时候一切正常。

直到今晚,想起来对比一下mac电脑上的pycharm里的库的版本和windows上的,先把numpy库版本降下来,运行时提示必须提高numpy版本才能用当前版本的pandas,然后我就把pandas的版本又换成和mac的一样,点击运行,发现终于不报错了!!

以上就是解决这个报错的心路历程,一度给我整的快哭了,尤其是同样的代码在mac上正常运行,windows上一直报错。😭

最终结论:
如果使用pycharm运行代码报 Process finished with exit code -1073741819 (0xC0000005) 错误,优先对代码里相关的引用库进行版本降级,大概率能解决问题。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐