<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hallo, <br>
<br>
ich habe ein Problem mit mulitprocessing - pickle error von
memoryview objekten <br>
Kann man das irgendwie anders lösen - evtl. ein globales shared
Objekt ?<br>
<br>
Vielen Dank !<br>
J. Sasse<br>
<br>
Traceback (most recent call last):<br>
File "D:\Pythonmodule\multiProzessTest3.py", line 27, in
<module><br>
for p in procs: p.start()<br>
File "C:\Python36\lib\multiprocessing\process.py", line 105, in
start<br>
self._popen = self._Popen(self)<br>
File "C:\Python36\lib\multiprocessing\context.py", line 223, in
_Popen<br>
return
_default_context.get_context().Process._Popen(process_obj)<br>
File "C:\Python36\lib\multiprocessing\context.py", line 322, in
_Popen<br>
return Popen(process_obj)<br>
File "C:\Python36\lib\multiprocessing\popen_spawn_win32.py", line
65, in __init__<br>
reduction.dump(process_obj, to_child)<br>
File "C:\Python36\lib\multiprocessing\reduction.py", line 60, in
dump<br>
ForkingPickler(file, protocol).dump(obj)<br>
TypeError: can't pickle memoryview objects<br>
<br>
<br>
import time<br>
from multiprocessing import Process, Value, Lock<br>
<br>
class Counter(object):<br>
def __init__(self, initval=0):<br>
self.val = Value('i', initval)<br>
<b>self.teil = memoryview(b'Binaere Konstante')</b><br>
self.lock = Lock()<br>
<br>
def increment(self):<br>
with self.lock:<br>
self.val.value += 1<br>
<br>
def value(self):<br>
with self.lock:<br>
return self.val.value<br>
<br>
def func(counter):<br>
for i in range(50):<br>
#time.sleep(0.01)<br>
counter.increment()<br>
<br>
if __name__ == '__main__':<br>
counter = Counter(0)<br>
procs = [Process(target=func, args=(counter,)) for i in
range(10)]<br>
<br>
for p in procs: p.start()<br>
for p in procs: p.join()<br>
<br>
print (counter.value())<br>
<br>
<br>
<pre class="moz-signature" cols="72">--
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</pre>
</body>
</html>