<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
Unter umständen geht es mit dill oder cloudpickle anstelle von pickle.<br /><br />pathos.multiprocess ist ein multiprocessing fork der dill verwendet und deutlich mehr objekte serialisieren kann als multiprocessing.<br /><br />Ob memoryview geht weiss ich aber nicht.<br />Roland<br /><br />
--
<br />
Securely sent with Tutanota. Claim your encrypted mailbox today!
<br />
<a href="https://tutanota.com" target="_blank" rel="noopener noreferrer">https://tutanota.com</a><br /><br />29. Jun 2017 15:19 by <a href="mailto:sasse@simply-running-systems.com" target="_blank" rel="noopener noreferrer">sasse@simply-running-systems.com</a>:<br /><br /><blockquote class="tutanota_quote" style="border-left: 1px solid #93A3B8; padding-left: 10px; margin-left: 5px;">
  
  
    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">-- 
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></blockquote>  </body>
</html>