一、问题描述
如下图:
翻译:
阴影显示的qNode来自外部范围。此检查检测到阴影名称为外部定义。
二、解决办法
产生这一问题的原因为:
- 该变量所在函数被调用的地方已存在同名变量。
- 函数内部定义的变量,和函数被调用的外部的变量一样。该变量就被称为shadows name
举个例子:
class Client(object):
def __init__(self, qNode, qSystem):
self.queue_node = qNode
self.queue_system = qSystem
def parse(self):
if dataType is node:
self.queue_node.put(data)
if dataType is system:
self.queue_system.put(data)
def main_client(qNode, qSystem):
app_client = QApplication(sys.argv)
app_client.setWindowIcon(QIcon('icon.jpg'))
clientWindow = Client(qNode, qSystem)
clientWindow.show()
sys.exit(app_client.exec_())
if __name__ == '__main__':
qNode = multiprocessing.Queue()
qSystem = multiprocessing.Queue()
pMainWindow = multiprocessing.Process(target=main_client, args=(qNode, qSystem))
pNode = multiprocessing.Process(target=main_node, args=(qNode,))
pSystem = multiprocessing.Process(target=main_system, args=(qSystem,))
pMainWindow.start()
pNode.start()
pSystem.start()
对于类Client,其初始化函数中qNode和qSystem,稍微改下名字即可。尽量不要让形参和实参名字一模一样。