2

不知道为什么会出现这个错误。我四处寻找无济于事。我决定尝试使用多处理模块让我的脚本运行多线程,如果我删除该代码,脚本运行良好。

所以我运行了调试器,它也没有遇到多线程代码的任何错误,这似乎有点奇怪。但是当我尝试正常运行脚本时,它会在 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

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

4

2 回答 2

3

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

python scripy.py
于 2013-02-11T20:15:13.113 回答
1

我收到错误代码的原因不同(使用 Py 3 和 Win 7)。从带有引号的 .ini 文件中读取文件名会破坏为 csv.DictWriter 函数打开的文件。删除“”修复它:

...
[CSVFILE]
#CfgCsvNamePattern="C:\\temp\\PenSim-%%s.csv"
CfgCsvNamePattern=C:/temp/PenSim%%s.csv
...
于 2013-12-19T12:54:47.770 回答