gpt4 book ai didi

python - Windows 上的多处理中断

转载 作者:太空狗 更新时间:2023-10-29 20:19:08 25 4
gpt4 key购买 nike

我在 Linux 上使用 Python 进行开发,但从未真正在 Windows 上遇到过此类问题。我正在使用 multiprocessing 库来加速计算,这对我来说在 Linux 上非常有效。

然而,在 Windows 上,事情并不顺利:

 * [INFO] Parsing 1 file using 2 threads

Traceback (most recent call last):
File "main.py", line 170, in <module>
master = ParsingMaster(parser, list(input_file), output_list, threads=num_threads)
Traceback (most recent call last):
File "main.py", line 39, in __init__
File "<string>", line 1, in <module>
self.input_process.start()
File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main
File "C:\Python26\lib\multiprocessing\process.py", line 104, in start
self._popen = Popen(self)
self = load(from_parent)
File "C:\Python26\lib\multiprocessing\forking.py", line 239, in __init__
File "C:\Python26\lib\pickle.py", line 1370, in load
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "C:\Python26\lib\multiprocessing\forking.py", line 162, in dump
ForkingPickler(file, protocol).dump(obj)
File "C:\Python26\lib\pickle.py", line 224, in dump
return Unpickler(file).load()
self.save(obj)
File "C:\Python26\lib\pickle.py", line 858, in load
File "C:\Python26\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python26\lib\pickle.py", line 419, in save_reduce
dispatch[key](self)
File "C:\Python26\lib\pickle.py", line 880, in load_eof
save(state)
File "C:\Python26\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
r aise EOFError
File "C:\Python26\lib\pickle.py", line 649, in save_dict
EOFError
self._batch_setitems(obj.iteritems())
File "C:\Python26\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Python26\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python26\lib\multiprocessing\forking.py", line 40, in dispatcher
self.save_reduce(obj=obj, *rv)
File "C:\Python26\lib\pickle.py", line 401, in save_reduce
save(args)
File "C:\Python26\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python26\lib\pickle.py", line 548, in save_tuple
save(element)
File "C:\Python26\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python26\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Python26\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python26\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Python26\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Python26\lib\pickle.py", line 306, in save
rv = reduce(self.proto)
File "C:\Python26\lib\multiprocessing\managers.py", line 458, in __reduce__
return type(self).from_address, \
AttributeError: type object 'SyncManager' has no attribute 'from_address'

我在 Windows 7 上对 Python 2.6 和 2.7 进行测试,一遍又一遍地遇到同样的错误。有人知道这是什么意思吗?

最佳答案

Windows 有限制,以下是您所看到的错误的相关部分:

Since Windows lacks os.fork() it has a few extra restrictions:

更多的可 pickle

Ensure that all arguments to Process.__init__() are picklable. This means, in particular, that bound or unbound methods cannot be used directly as the target argument on Windows — just define a function and use that instead.

Also, if you subclass Process then make sure that instances will be picklable when the Process.start() method is called.

这意味着某些东西作为参数传递给 Process.__init__() isn't able to be pickled or unpickled (Python 中的序列化)。什么是 SyncManager 它提示无法在该对象上找到属性 AttributeError: type object 'SyncManager' has no attribute 'from_address',这可能是你的根本原因. SyncManager 对象真的可以 pickle 吗,does it meet the pickle rules

如果您从 command line on Windows, you can't do that 运行它显然。

不要那样做。将代码保存在一个文件中,然后使用以下命令从该文件运行它:

python myfile.py

这将解决您的问题。

关于python - Windows 上的多处理中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9670926/

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