multiprocessing.Process 子类适用于 Linux,但不适用于 Windows

发布于 2024-08-18 00:58:26 字数 2726 浏览 2 评论 0原文

我试图让 python-gasp 在 Windows 上工作,但是当我这样做时 进口喘息; Gasp.begin_graphics() 我得到以下回溯:

  File "C:\Python26\lib\site-packages\gasp\backend.py", line 142, in create_screen

    screen.updater.start()

  File "C:\Python26\lib\multiprocessing\process.py", line 104, in start

    self._popen = Popen(self)

  File "C:\Python26\lib\multiprocessing\forking.py", line 239, in __init__

    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

    self.save(obj)

  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 286, in save

    f(self, obj) # Call unbound method with explicit self

  File "C:\Python26\lib\pickle.py", line 725, in save_inst

    save(stuff)

  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 331, in save

    self.save_reduce(obj=obj, *rv)

  File "C:\Python26\lib\pickle.py", line 396, in save_reduce

    save(cls)

  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 748, in save_global

    (obj, module, name))

PicklingError: Can't pickle <class 'multiprocessing.process._MainProcess'>: it's not found as multiprocessing.process._MainProcess

知道为什么我在 Windows XP 上收到此错误但在 Ubuntu Linux 9.04 上没有收到此错误吗?

看起来 screen.updaterUpdater(multiprocessing.Process) 的实例 (def),如果有帮助的话。有问题的文件位于 http://bazaar.launchpad.net/~gasp-dev/gasp-core/main/annotate/head%3A/gasp/backend.py

I'm trying to get python-gasp working on Windows, but when I do import gasp; gasp.begin_graphics() I get the following traceback:

  File "C:\Python26\lib\site-packages\gasp\backend.py", line 142, in create_screen

    screen.updater.start()

  File "C:\Python26\lib\multiprocessing\process.py", line 104, in start

    self._popen = Popen(self)

  File "C:\Python26\lib\multiprocessing\forking.py", line 239, in __init__

    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

    self.save(obj)

  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 286, in save

    f(self, obj) # Call unbound method with explicit self

  File "C:\Python26\lib\pickle.py", line 725, in save_inst

    save(stuff)

  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 331, in save

    self.save_reduce(obj=obj, *rv)

  File "C:\Python26\lib\pickle.py", line 396, in save_reduce

    save(cls)

  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 748, in save_global

    (obj, module, name))

PicklingError: Can't pickle <class 'multiprocessing.process._MainProcess'>: it's not found as multiprocessing.process._MainProcess

Any idea why I'm getting this error on Windows XP but not on Ubuntu Linux 9.04?

It looks like screen.updater is an instance of Updater(multiprocessing.Process) (def), if that helps. The file in question is at http://bazaar.launchpad.net/~gasp-dev/gasp-core/main/annotate/head%3A/gasp/backend.py

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

俯瞰星空 2024-08-25 00:58:26

您的 Updater 类有一个成员 screen,它本身有一个成员 process,它接收 multiprocessing.current_process() 的值代码>.

当您调用 updater.start() 时,它会尝试 pickle 更新程序。这种情况只发生在 Windows 上,因为 Linux 使用 fork() 而不是 pickling。但是,无法对当前进程对象进行 pickle,并且会引发异常。

要解决此问题,您可以删除 process 成员。

Your Updater class has a member screen, which itself has a member process which receives the value of multiprocessing.current_process().

When you call updater.start(), it tries to pickle the updater. This only happens on Windows because Linux uses fork() instead of pickling. However, the current-process object cannot be pickled and the exception is raised.

To fix this, you can remove the process member.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文