Skip to main content
Post Closed as "Needs more focus" by PolyGeo
deleted 61 characters in body; edited tags; added 5 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I spent quite a bit of time looking on how to use the multiprocessing package, but couldn't find anything on how to use it inside a plugin in QGIS. I am developing a plugin that does some optimization for several elements. I would like to parallelize it.

I found a useful link on multi-threading inside a python plugin (http://snorf.net/blog/2013/12/07/multithreading-in-qgis-python-plugins/), but nothing on using the multiprocessing module, which might be easier?

I have been trying with a very basic example. I am only showing the run function from the plugin here:

def run(self):
    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()
    
    # Run the dialog event loop
    result = self.dlg.exec_()
    
    # See if OK was pressed and run code
    if result:
        #Get number of cores
        nProcs = mp.cpu_count()
                
        #Start a Process
        p = mp.Pool(nProcs)
        
        #Define function     
            def cube(x):
                return x**3
        
        #Run parallel        
        results = p.map(cube, range(1,7))

When I run this code from the plugin in QGIS, it opens several QGIS windows, which then return errors (can't load layers, etc.). What

What am I missing? 

Do I need to start a worker first on another thread and then use multiprocessing there? 

Or would we use another function from multiprocessing?

Please let me know if the question needs edits. II am working under windows 7, using QGIS 2.10.

Thanks,

I spent quite a bit of time looking on how to use the multiprocessing package, but couldn't find anything on how to use it inside a plugin in QGIS. I am developing a plugin that does some optimization for several elements. I would like to parallelize it.

I found a useful link on multi-threading inside a python plugin (http://snorf.net/blog/2013/12/07/multithreading-in-qgis-python-plugins/), but nothing on using the multiprocessing module, which might be easier?

I have been trying with a very basic example. I am only showing the run function from the plugin here:

def run(self):
    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()
    
    # Run the dialog event loop
    result = self.dlg.exec_()
    
    # See if OK was pressed and run code
    if result:
        #Get number of cores
        nProcs = mp.cpu_count()
                
        #Start a Process
        p = mp.Pool(nProcs)
        
        #Define function     
            def cube(x):
                return x**3
        
        #Run parallel        
        results = p.map(cube, range(1,7))

When I run this code from the plugin in QGIS, it opens several QGIS windows, which then return errors (can't load layers, etc.). What am I missing? Do I need to start a worker first on another thread and then use multiprocessing there? Or would we use another function from multiprocessing?

Please let me know if the question needs edits. I am working under windows 7, using QGIS 2.10.

Thanks,

I spent quite a bit of time looking on how to use the multiprocessing package, but couldn't find anything on how to use it inside a plugin in QGIS. I am developing a plugin that does some optimization for several elements. I would like to parallelize it.

I found a useful link on multi-threading inside a python plugin (http://snorf.net/blog/2013/12/07/multithreading-in-qgis-python-plugins/), but nothing on using the multiprocessing module, which might be easier?

I have been trying with a very basic example. I am only showing the run function from the plugin here:

def run(self):
    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()
    
    # Run the dialog event loop
    result = self.dlg.exec_()
    
    # See if OK was pressed and run code
    if result:
        #Get number of cores
        nProcs = mp.cpu_count()
                
        #Start a Process
        p = mp.Pool(nProcs)
        
        #Define function     
            def cube(x):
                return x**3
        
        #Run parallel        
        results = p.map(cube, range(1,7))

When I run this code from the plugin in QGIS, it opens several QGIS windows, which then return errors (can't load layers, etc.).

What am I missing? 

Do I need to start a worker first on another thread and then use multiprocessing there? 

Or would we use another function from multiprocessing?

I am working under windows 7, using QGIS 2.10.

Tweeted twitter.com/StackGIS/status/805341019105587200
Fix spelling
Source Link
Michael Stimson
  • 25.7k
  • 2
  • 35
  • 75

I spent quite a bit of time looking on how to use the multiprocessing package, but couldn't find anything on how to use it inside a puglinplugin in QgisQGIS. I am developing a plugin that does some optimization for several elements. I would like to parallelize it.

I found a useful link on multi-threading inside a python plugin (http://snorf.net/blog/2013/12/07/multithreading-in-qgis-python-plugins/), but nothing on using the multiprocessing module, which might be easier?

I have been trying with a very basic example. I am only showing the run function from the plugin here:

def run(self):
    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()
    
    # Run the dialog event loop
    result = self.dlg.exec_()
    
    # See if OK was pressed and run code
    if result:
        #Get number of cores
        nProcs = mp.cpu_count()
                
        #Start a Process
        p = mp.Pool(nProcs)
        
        #Define function     
            def cube(x):
                return x**3
        
        #Run parallel        
        results = p.map(cube, range(1,7))

When I run this code from the plugin in QgisQGIS, it opens several QgisQGIS windows, which then return errors (can't load layers, etc.). What am I missing? Do I need to start a worker first on another thread and then use multiprocessing there? Or whouldwould we use another function from multiprocessing?

Please let me know if the question needs edits. I am working unserunder windows 7, using QgisQGIS 2.10.

Thanks,

I spent quite a bit of time looking on how to use the multiprocessing package, but couldn't find anything on how to use it inside a puglin in Qgis. I am developing a plugin that does some optimization for several elements. I would like to parallelize it.

I found a useful link on multi-threading inside a python plugin (http://snorf.net/blog/2013/12/07/multithreading-in-qgis-python-plugins/), but nothing on using the multiprocessing module, which might be easier?

I have been trying with a very basic example. I am only showing the run function from the plugin here:

def run(self):
    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()
    
    # Run the dialog event loop
    result = self.dlg.exec_()
    
    # See if OK was pressed and run code
    if result:
        #Get number of cores
        nProcs = mp.cpu_count()
                
        #Start a Process
        p = mp.Pool(nProcs)
        
        #Define function     
            def cube(x):
                return x**3
        
        #Run parallel        
        results = p.map(cube, range(1,7))

When I run this code from the plugin in Qgis, it opens several Qgis windows, which then return errors (can't load layers, etc.). What am I missing? Do I need to start a worker first on another thread and then use multiprocessing there? Or whould we use another function from multiprocessing?

Please let me know if the question needs edits. I am working unser windows 7, using Qgis 2.10.

Thanks,

I spent quite a bit of time looking on how to use the multiprocessing package, but couldn't find anything on how to use it inside a plugin in QGIS. I am developing a plugin that does some optimization for several elements. I would like to parallelize it.

I found a useful link on multi-threading inside a python plugin (http://snorf.net/blog/2013/12/07/multithreading-in-qgis-python-plugins/), but nothing on using the multiprocessing module, which might be easier?

I have been trying with a very basic example. I am only showing the run function from the plugin here:

def run(self):
    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()
    
    # Run the dialog event loop
    result = self.dlg.exec_()
    
    # See if OK was pressed and run code
    if result:
        #Get number of cores
        nProcs = mp.cpu_count()
                
        #Start a Process
        p = mp.Pool(nProcs)
        
        #Define function     
            def cube(x):
                return x**3
        
        #Run parallel        
        results = p.map(cube, range(1,7))

When I run this code from the plugin in QGIS, it opens several QGIS windows, which then return errors (can't load layers, etc.). What am I missing? Do I need to start a worker first on another thread and then use multiprocessing there? Or would we use another function from multiprocessing?

Please let me know if the question needs edits. I am working under windows 7, using QGIS 2.10.

Thanks,

Source Link
Olivier
  • 419
  • 2
  • 11

Using Multiprocessing inside a plugin in Qgis

I spent quite a bit of time looking on how to use the multiprocessing package, but couldn't find anything on how to use it inside a puglin in Qgis. I am developing a plugin that does some optimization for several elements. I would like to parallelize it.

I found a useful link on multi-threading inside a python plugin (http://snorf.net/blog/2013/12/07/multithreading-in-qgis-python-plugins/), but nothing on using the multiprocessing module, which might be easier?

I have been trying with a very basic example. I am only showing the run function from the plugin here:

def run(self):
    """Run method that performs all the real work"""
    # show the dialog
    self.dlg.show()
    
    # Run the dialog event loop
    result = self.dlg.exec_()
    
    # See if OK was pressed and run code
    if result:
        #Get number of cores
        nProcs = mp.cpu_count()
                
        #Start a Process
        p = mp.Pool(nProcs)
        
        #Define function     
            def cube(x):
                return x**3
        
        #Run parallel        
        results = p.map(cube, range(1,7))

When I run this code from the plugin in Qgis, it opens several Qgis windows, which then return errors (can't load layers, etc.). What am I missing? Do I need to start a worker first on another thread and then use multiprocessing there? Or whould we use another function from multiprocessing?

Please let me know if the question needs edits. I am working unser windows 7, using Qgis 2.10.

Thanks,