我正在使用python的Multiprocess.Pool使用多个进程绘制一些数据,如下所示:
class plotDriver:
def plot(self, parameterList):
numberOfWorkers = len(parameterList)
pool = Pool(numberOfWorkers)
pool.map(plotWorkerFunction, parameterList)
pool.close()
pool.join()
Run Code Online (Sandbox Code Playgroud)
这是我班级的简化版本,驱动程序还包含我选择省略的其他内容.这plotWorkderFunction是一个单线程函数,它导入matplotlib并执行所有绘图和设置图形样式并将图形保存到一个pdf文件,并且每个工作程序不与另一个工作程序交互.
我需要多次调用这个绘图函数,因为我有很多parameterList,如下所示:
parameters = [parameterList0, parameterList1, ... parameterListn]
for param in parameters:
driver = PlotDriver()
driver.plot(param)
Run Code Online (Sandbox Code Playgroud)
如果parameters只包含一个parameterList(for循环只运行一次),代码似乎工作正常.但是,只要parameters包含多个元素,它就会一直失败,并且第二次在循环中发生以下错误消息.
Traceback (most recent call last):
File "plot.py", line 59, in <module>
plottingDriver.plot(outputFile_handle)
File "/home/yingryic/PlotDriver.py", line 69, in plot
pool.map(plotWrapper, workerParamList)
File "/home/yingryic/.conda/envs/pp/lib/python2.7/multiprocessing/pool.py", line 251, in map
return self.map_async(func.iterable, chunksize).get()
File "/home/yingryic/.conda/envs/pp/python2.7/multiprocessing/pool.py", line 567, in get
raise self._value
RuntimeError: In …Run Code Online (Sandbox Code Playgroud) 我对奇怪的重复模板遇到以下问题,当我尝试访问 CRTP 基类的数据成员时出现问题。
\n\ntemplate<typename T>\nstruct Base {\n int protectedData=10;\n};\n\nstruct Derived : public Base<Derived> {\npublic:\n void method() {\n std::cout<<protectedData<<std::endl;\n };\n};\n\nint main ()\n{\n Derived a;\n a.method();\n}\nRun Code Online (Sandbox Code Playgroud)\n\n上面的代码编译并运行良好,我可以打印“10”,但如果我有模板化的派生类,例如:
\n\ntemplate<typename T>\nstruct Base {\n int protectedData=10;\n};\n\ntemplate<typename T>\nstruct Derived : public Base<Derived<T> > {\npublic:\n void method() {\n std::cout<<protectedData<<std::endl;\n };\n};\n\nclass A{};\n\nint main ()\n{\n Derived<A> a;\n a.method();\n}\nRun Code Online (Sandbox Code Playgroud)\n\n类 A 只是一个充当模板参数的虚拟类。但编译器抱怨找不到“protectedData”。错误信息如下:
\n\ng++-4.9 test.cc -Wall -std=c++1y -Wconversion -Wextra\ntest.cc: In member function \xe2\x80\x98void Derived<T>::method()\xe2\x80\x99:\ntest.cc:26:11: error: \xe2\x80\x98protectedData\xe2\x80\x99 was not declared in this scope\n cout<<protectedData<<endl;\nRun Code Online (Sandbox Code Playgroud)\n