gpt4 book ai didi

Python 多处理 builtins.IOError : [Errno 22] Invalid argument

转载 作者:行者123 更新时间:2023-11-28 22:56:56 25 4
gpt4 key购买 nike

不确定为什么会出现此错误。我四处搜寻无果。我决定尝试使用多处理模块让我的脚本以多线程方式运行,如果我删除该代码,脚本运行良好。

所以我运行了调试器,它也没有遇到任何多线程代码的错误,这似乎有点奇怪。但是当我尝试正常运行脚本时,它会在 3.2.3 下打印:

Python 3.2.3 (default, Apr 11 2012, 07:12:16) [MSC v.1500 64 bit (AMD64)]
Type "help", "copyright", "credits" or "license" for more information.
[evaluate scratch.py]
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python32\Lib\multiprocessing\forking.py", line 369, in main
self = load(from_parent)
AttributeError: 'module' object has no attribute 'search_letters_in_words'
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE 4.1\src\debug\tserver\_sandbox.py", line 122, in <module>
File "C:\Python32\Lib\multiprocessing\process.py", line 132, in start
self._popen = Popen(self)
File "C:\Python32\Lib\multiprocessing\forking.py", line 269, in __init__
to_child.close()
builtins.IOError: [Errno 22] Invalid argument

编辑:我切换到 3.3 看看会发生什么,它不一致地始终抛出这两个回溯之一:

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)]
Type "help", "copyright", "credits" or "license" for more information.
[evaluate scratch.py]
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python33\Lib\multiprocessing\forking.py", line 344, in main
self = load(from_parent)
AttributeError: 'module' object has no attribute 'search_letters_in_words'
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE 4.1\src\debug\tserver\_sandbox.py", line 122, in <module>
File "C:\Python33\Lib\multiprocessing\process.py", line 111, in start
self._popen = Popen(self)
File "C:\Python33\Lib\multiprocessing\forking.py", line 243, in __init__
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "C:\Python33\Lib\multiprocessing\forking.py", line 160, in dump
ForkingPickler(file, protocol).dump(obj)
builtins.BrokenPipeError: [Errno 32] Broken pipe

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)]
Type "help", "copyright", "credits" or "license" for more information.
[evaluate scratch.py]
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python33\Lib\multiprocessing\forking.py", line 344, in main
self = load(from_parent)
AttributeError: 'module' object has no attribute 'search_letters_in_words'

编辑#2 从命令行调用时添加回溯:

D:\Python\PythonRepo>scratch.py > d:\download\error.txt
Traceback (most recent call last):
File "D:\Python\PythonRepo\scratch.py", line 122, in <module>
thread.start()
File "C:\Python32\Lib\multiprocessing\process.py", line 131, in start
from .forking import Popen
File "C:\Python32\Lib\multiprocessing\forking.py", line 180, in <module>
import _subprocess
ImportError: No module named '_subprocess'

这是我到目前为止编写的多处理代码。它可能是(哈,我在跟谁开玩笑,可能是!)错误,但我不确定哪里出了问题,因为它看起来是正确的(不总是正确的吗?)。

wordList = pickle.load( open( r'd:\download\allwords.pickle', 'rb')) #a list
combos = make_letter_combinations(3) # a list
split = split_list_multi(combos) #2 item tuple with a dict and a number
if __name__ == '__main__':
multiprocessing.freeze_support()
jobs = []
for num in range(split[1]):
listLetters = split[0][str(num)] #a list
thread = multiprocessing.Process(target=search_letters_in_words, args=(listLetters,wordList))
jobs.append(thread)
thread.start()
for j in jobs:
j.join()

编辑:这是 search_letters_in_words_ 函数:

def search_letters_in_words(listOfLetters,wordlist):
results = {}
for letters in listOfLetters:
results[letters] = [i for i in wordlist if letters in i]
return results

如果有人能指出我做错了什么,我将不胜感激!

最佳答案

尝试从命令行运行脚本,而不是通过 Wing IDE:

python scripy.py

关于Python 多处理 builtins.IOError : [Errno 22] Invalid argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14819987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com