[python-users] Problem multiprocessing
Joachim Sasse
sasse at simply-running-systems.com
Do Jun 29 15:19:29 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())
--
Mit freundlichen Grüßen
Joachim Sasse
simply running systems GmbH&CO.KG
Grauten Ihl 27
48301 Nottuln
02502/4124724
Geschäftsführer: Joachim Sasse
HRA 9162 Amtsgericht Coesfeld
persönlich haftender Gesellschafter:
simply running systems Verwaltungs GmbH
Amtsgericht Coesfeld HRB 16425
-------------- nächster Teil --------------
Ein Dateianhang mit HTML-Daten wurde abgetrennt...
URL: <http://lists.uni-koeln.de/pipermail/python-users/attachments/20170629/f0b928e2/attachment.html>
Mehr Informationen über die Mailingliste python-users