python多核跑miasm

博客内容涉及到Python多进程编程中出现的错误,具体表现为在尝试启动新进程前,当前进程尚未完成初始化。错误提示强调可能未使用fork方式启动子进程,并提醒在主模块中正确使用`if __name__ == '__main__':`和`freeze_support()`。同时,代码中存在局部变量`Machine`在使用前未被正确赋值。解决方法包括定义全局变量`Machine`和检查多进程启动逻辑。
摘要由CSDN通过智能技术生成
        is not going to be frozen to produce an executable.    _check_not_importing_main()
  File "C:\Python38\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
  File "C:\Python38\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main

  File "C:\Python38\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
    raise RuntimeError('''
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.    raise RuntimeError('''
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

Traceback (most recent call last):

解决需要定义main函数

Process Process-6:
Process Process-8:
Process Process-7:
Traceback (most recent call last):
  File "C:\Python38\lib\multiprocessing\process.py", line 315, in _bootstrap
    self.run()
  File "C:\Python38\lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python27\my_project\nulti_core\unicorn.py", line 56, in job
    Machine=Machine('x86_32')
Traceback (most recent call last):
Traceback (most recent call last):
UnboundLocalError: local variable 'Machine' referenced before assignment
  File "C:\Python38\lib\multiprocessing\process.py", line 315, in _bootstrap
    self.run()
  File "C:\Python38\lib\multiprocessing\process.py", line 315, in _bootstrap
    self.run()
  File "C:\Python38\lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python38\lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python27\my_project\nulti_core\unicorn.py", line 56, in job
    Machine=Machine('x86_32')
  File "C:\Python27\my_project\nulti_core\unicorn.py", line 56, in job
    Machine=Machine('x86_32')
UnboundLocalError: local variable 'Machine' referenced before assignment
UnboundLocalError: local variable 'Machine' referenced before assignment

解决:

global Machine

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值