Python Forum
Python 3.5 Instantiate and manipulate object with multiprocessing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 3.5 Instantiate and manipulate object with multiprocessing
#1
Hello, I am looking for a solution to be able to instantiate an object that will exploit another heart of cpu all by manipulating it from another process.
Currently the only solution I found is to use pickle.
But :
1) But I find this solution low performing
2) I can not for example create a tkinter window in my object

This is my code, Would you have more optimal solutions to offer me ?

  import multiprocessing as m import pickle   class Store:     pass   class Shareable:     def __init__(self, size = 2**10):         object.__setattr__(self, 'store', m.Array('B', size))         o = Store() # This object will hold all shared values         s = pickle.dumps(o)         store(object.__getattribute__(self, 'store'), s)       def __getattr__(self, name):         s = load(object.__getattribute__(self, 'store'))         o = pickle.loads(s)         return getattr(o, name)       def __setattr__(self, name, value):         s = load(object.__getattribute__(self, 'store'))         o = pickle.loads(s)         setattr(o, name, value)         s = pickle.dumps(o)         store(object.__getattribute__(self, 'store'), s)   def store(arr, s):     for i, ch in enumerate(s):         arr[i] = ch   def load(arr):     l = arr[:]     return bytes(arr)   class Foo(Shareable):     def __init__(self):         super().__init__()         self.f = 1         self.f2 = 1         self.mylist=[0,1,2,3,4,5,6]       def foo(self):         self.f += 1         """while True:             self.f2+=1"""   def Otherprocess(s):     print("Process2 :")     print(s.f)     s.mylist=[0]     """while True:         s.f2+=1"""   if __name__ == '__main__':     import multiprocessing as m     import time     s = Foo()     print(s.f)     p = m.Process(target=s.foo, args=())     p.start()     #p.join()     p2 = m.Process(target=Otherprocess, args=(s,))     p2.start()     time.sleep(1)     print("Process1 :")     print(s.f)     print(s.mylist)
Reply
#2
Have you taken a look at this? https://docs.python.org/3/library/multip...-processes
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  issue with multiprocessing in embeded python otaolafr 1 860 Mar-05-2025, 06:24 PM
Last Post: deanhystad
  Extract args=, value that was passed to Multiprocessing.Proc object during runtime? haihal 1 1,089 Dec-08-2024, 07:04 AM
Last Post: Gribouillis
  Is this a multiprocessing bug in Python - or am I doing something wrong? haimat 1 4,563 Oct-18-2023, 06:07 AM
Last Post: absalom1
  How do I instantiate a class with **kwargs? palladium 6 16,613 Feb-16-2023, 06:10 PM
Last Post: deanhystad
  python multiprocessing help -- to extract 10 sql table into csv mg24 3 3,331 Nov-20-2022, 11:50 PM
Last Post: mg24
  Openpyxl manipulate excel write formula SamLiu 0 3,648 Nov-04-2022, 03:00 PM
Last Post: SamLiu
  python multiprocessing to download sql table mg24 5 3,619 Oct-31-2022, 03:53 PM
Last Post: Larz60+
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 2,801 Sep-19-2022, 02:32 AM
Last Post: Xeno
  python update binary object (override delivered Object properties) pierre38 4 3,690 May-19-2022, 07:52 AM
Last Post: pierre38
  Python multiprocessing Pool apply async wait for process to complete sunny9495 6 13,615 Apr-02-2022, 06:31 AM
Last Post: sunny9495

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.