Note that there are some explanatory texts on larger screens.

plurals
  1. POdataexchange between two simultanous running functions in Python
    primarykey
    data
    text
    <p>as someone who explores the new and mighty world of Python, I am running into an understanding problem for my coding and it would be great if someone could help me on this one.</p> <p>To make my problem simple I have made an example. Lets say, I have two functions, running via multiprocessing simultaneously. One is a permanent data listener and one prints the value of it out. In addition I have one object which owns the data, data is set via set/get. So the challenge is how both function can access the data without putting it to global. I guess my lack of understanding is somewhere in how to transfer the object between functions.</p> <p>NOTE : both functions do not need to be in sync and the while is just for endless loop. It just how to bring the data over.</p> <p>This gives a code like (I know it is not working, just to get the idea) :</p> <pre><code>import multiprocessing #simply a data object class data(object): def __init__(self): self.__value = 1 def set_value(self, value): self.__value = value def get_value(self): return self.__value # Data listener def f1(count): zae = 0 while True: zae += 1 count.set_value = zae def f2(count): while True: print (count.get_value) #MainPart if __name__ == '__main__': print('start') count = data() jobs = [] p1 = multiprocessing.Process(target =f1(count)) p2 = multiprocessing.Process(target =f2(count)) jobs.append(p1) jobs.append(p2) p1.start() p2.start() print ('end') </code></pre> <p>Please enlight me,</p> <p>regards AdrianMonk</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload