LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PyGTK3 progress bar and multiprocessing (https://www.linuxquestions.org/questions/programming-9/pygtk3-progress-bar-and-multiprocessing-4175635324/)

aihaike 07-31-2018 04:03 AM

PyGTK3 progress bar and multiprocessing
 
Dear all,

I'm developing a PyGTK3 application (Linux) that copy several files to a server at the same time.
Basically, I have a batch of progress bar for each copy.
I run each copy in a process using the multiprocessing module.
In order to update the progress bar, I passed the object to the function that copy and do a set_fractional but that didn't work. I also tried to pass the value in a list as since it's mutable but still can't get the new value.

All multiprocessing examples I find talk about getting results but not about getting individual data during the process run.
That's be great if someone could shed some light on this matter to me.

Thanks.

aihaike 07-31-2018 06:00 AM

In fact it seems the issue is summarized by the following.

In a python shell I define a function:

Code:

>>> def myfct2(n):
...  for i in range(len(n)):
...    n[i] = i
...    time.sleep(3)

Then execute it with a 'None' list:

Code:

N=[None]*4
>>> N
[None, None, None, None]
>>> myfct(N)
>>> N
[0, 1, 2, 3]

The list gets change because it's mutable.

Now, if I do the same thing in a process it behaves differently:

Code:

proc=multiprocessing.Process( target=myfct,args=(N,),daemon=True)

N=[None]*4

>>> proc.start()
>>> proc.is_alive()
True
>>> proc.is_alive()
True
>>> proc.is_alive()
True
>>> proc.is_alive()
True
>>> proc.is_alive()
True
>>> proc.is_alive()
False
>>> N
[None, None, None, None]

Can someone tell me how can I modify a mutable object passed to a function argument through a process ?


All times are GMT -5. The time now is 06:08 AM.