[python-users] Problem mit multiprocessing

Joachim Sasse sassec1 at t-online.de
Do Jun 29 15:51:37 CEST 2017


Hallo,

ich habe ein Problem mit mulitprocessing - pickle error von memoryview 
objekten
Kann man das irgendwie anders lösen - evtl.  ein globales shared Objekt ?

Vielen Dank !
J. Sasse

Traceback (most recent call last):
   File "D:\Pythonmodule\multiProzessTest3.py", line 27, in <module>
     for p in procs: p.start()
   File "C:\Python36\lib\multiprocessing\process.py", line 105, in start
     self._popen = self._Popen(self)
   File "C:\Python36\lib\multiprocessing\context.py", line 223, in _Popen
     return _default_context.get_context().Process._Popen(process_obj)
   File "C:\Python36\lib\multiprocessing\context.py", line 322, in _Popen
     return Popen(process_obj)
   File "C:\Python36\lib\multiprocessing\popen_spawn_win32.py", line 65, 
in __init__
     reduction.dump(process_obj, to_child)
   File "C:\Python36\lib\multiprocessing\reduction.py", line 60, in dump
     ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle memoryview objects


import time
from multiprocessing import Process, Value, Lock

class Counter(object):
     def __init__(self, initval=0):
         self.val = Value('i', initval)
*self.teil = memoryview(b'Binaere Konstante')*
         self.lock = Lock()

     def increment(self):
         with self.lock:
             self.val.value += 1

     def value(self):
         with self.lock:
             return self.val.value

def func(counter):
     for i in range(50):
         #time.sleep(0.01)
         counter.increment()

if __name__ == '__main__':
     counter = Counter(0)
     procs = [Process(target=func, args=(counter,)) for i in range(10)]

     for p in procs: p.start()
     for p in procs: p.join()

     print (counter.value())


-------------- nächster Teil --------------
Ein Dateianhang mit HTML-Daten wurde abgetrennt...
URL: <http://lists.uni-koeln.de/pipermail/python-users/attachments/20170629/a587fd6b/attachment.html>


Mehr Informationen über die Mailingliste python-users