瀏覽代碼

wxGUI/animation: autodetect number of CPUs

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58402 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 11 年之前
父節點
當前提交
ed480187e6
共有 2 個文件被更改,包括 14 次插入3 次删除
  1. 3 3
      gui/wxpython/animation/controller.py
  2. 11 0
      gui/wxpython/animation/utils.py

+ 3 - 3
gui/wxpython/animation/controller.py

@@ -23,7 +23,7 @@ from grass.imaging import writeAvi, writeGif, writeIms, writeSwf
 from animation.temporal_manager import TemporalManager
 from animation.dialogs import InputDialog, EditDialog, ExportDialog
 from animation.utils import TemporalMode, Orientation, RenderText, WxImageToPil, \
-    sampleCmdMatrixAndCreateNames, layerListToCmdsMatrix, HashCmds
+    sampleCmdMatrixAndCreateNames, layerListToCmdsMatrix, HashCmds, getCpuCount
 from animation.data import AnimationData
 
 
@@ -354,7 +354,7 @@ class AnimationController(wx.EvtHandler):
             else:
                 self._load3DData(animData)
             self._loadLegend(animData)
-        self.bitmapProvider.Load(nprocs=4)
+        self.bitmapProvider.Load(nprocs=getCpuCount())
         # clear pools
         self.bitmapPool.Clear()
         self.mapFilesPool.Clear()
@@ -429,7 +429,7 @@ class AnimationController(wx.EvtHandler):
     def Reload(self):
         self.EndAnimation()
 
-        self.bitmapProvider.Load(force=True)
+        self.bitmapProvider.Load(nprocs=getCpuCount(), force=True)
 
         self.EndAnimation()
 

+ 11 - 0
gui/wxpython/animation/utils.py

@@ -20,6 +20,7 @@ This program is free software under the GNU General Public License
 import os
 import wx
 import hashlib
+from multiprocessing import cpu_count
 try:
     from PIL import Image
     hasPIL = True
@@ -309,3 +310,13 @@ def sampleCmdMatrixAndCreateNames(cmdMatrix, sampledSeries):
             namesList.append(None)
     assert(j == len(cmdMatrix) - 1)
     return namesList
+
+
+def getCpuCount():
+    """!Returns number of available cpus.
+    If fails, default (4) is returned.
+    """
+    try:
+        return cpu_count()
+    except NotImplementedError:
+        return 4