In case timer is bad for you as well add it to counter function. Add at the start: start_time = time.perf_counter() Then at the end end_time = time.perf_counter() print("Time taken by counter: ", end_time - start_time, "seconds")
Hi Bro! I have been following this course as I teach myself coding and it has been a HUGE help! I did have question about the "time.perf_counter()" call. For whatever reason whenever I run this it returns with something like this : "finished in: 584461.4056658 seconds" when in reality it took about 11 seconds to finish. I am not sure why this is occurring as I have typed out everything that same you have. Thanks again for all the videos, they have been fantastic!
Hello. I've been watching the full python course and I had this same problem. I don't know if you already got a solution or even if you just stopped thinking about it. I created a variable in the beginning of the function main and one in the end (of that same function), both associated to a time.perf_counter() method. In the end i printed the difference between the last perf_counter() and the first one and now it looks like it works. I'm not sure if this is the right approach but I tried with 8 cores and, in my case, the result is between 7 and 9 seconds.
@@henriquemanuelcordeirorodr2523 Bro thank you so much this was an absolute pain for a while. It seems not known or something on the rest of the internet lol.
Thanks! great content and explanation! Can you help with instruction how to combine concurrency (such as asyncio or asyncioscheduler with multiprocessing)? Example, I want 2 processes dedicated to computing, and the other 2 dedicated for I/O tasks.
I understand that Python multi-processing and multi-threading can accelerate running independent tasks. However, If I have 10 tasks sequentially and each one's input rely on the previous one's output, is it still possible to accelerate using parallel computing or parallel processing? Any perspective from software or hardware will be appreciated!
Hi Bro def main(): print("cpu count:", cpu_count()) If I use: a = Process(target=counter(500000000)) b = Process(target=counter(500000000)) I get: cpu count: 8 processing... Done! finished in: 43 seconds instead of: a = Process(target=counter, args=(500000000,)) b = Process(target=counter, args=(500000000,)) I get the same results but cpu count: 8 processing... Done! finished in: 22 seconds It seem I get the same results but the time comsuption is so much higher .... Any explanation.... Thanks
doesnt work for me at all. ImportError: cannot import name 'Process' from partially initialized module 'multiprocessing' (most likely due to a circular import) it looks like those functions doesn't exist in library or sth ? also already in this part "from multiprocessing import Process, cpu_count" it cant find reference to Process, cpu_count...any ideas what's going on?
@everyone I have a question. How does it come, that my time.perf_counter() does not give out the time, since the programm started. If I want to achieve that, I have to type in x = time.perf_counter() at the start of the programm and subtract the perf_counter() from the end by x and then I get the right time. Sorry if my english is not very good. Hope someone can help me with that problem
Hey bro, when the complete task was divided into two processes, why was the time taken not halved? and, are there any disadvantages of processes that threads doesn't have? You advised to use threads for io bound operations in a previous video... Thanks!
I don't exactly know the full reason, but like Bro Code mentioned: every time you create a process there is a significant overhead in terms of time. Which is part of the reason why it's not exactly half.
I think it is using another time as its reference. I had similar issue. I was able to fix by defining t1 = time.perf_counter() at beginning, t2 = time.perf_counter() at end, then printing t2 - t1 seconds.
@@lucamassimosantilli8533 Yeah same. I look at codes again and again, maybe missed some code or typed wrong code that changed the type of "sec". But nothing. Maybe someone sees and helps some other time. Cheers.
add this to the start : start = time.perf_counter() and add this to the print function : time.perf_counter()-start basically starting a timer and then subtracting it
# ***********************************
# Python multiprocessing
# ***********************************
# multiprocessing = running tasks in parallel on different cpu cores, bypasses GIL used for threading
# multiprocessing = better for cpu bound tasks (heavy cpu usage)
# multithreading = better for io bound tasks (waiting around)
from multiprocessing import Process, cpu_count
import time
def counter(num):
count = 0
while count < num:
count += 1
def main():
print("cpu count:", cpu_count())
a = Process(target=counter, args=(500000000,))
b = Process(target=counter, args=(500000000,))
a.start()
b.start()
print("processing...")
a.join()
b.join()
print("Done!")
print("finished in:", time.perf_counter(), "seconds")
if __name__ == '__main__':
main()
# ***********************************
Thanks bro
I came as beginner, and now feel quite assured as an intermediate. Thanks so much
Finding this extremely helpful even 2 years later! you are the best!
In case timer is bad for you as well add it to counter function. Add at the start:
start_time = time.perf_counter()
Then at the end
end_time = time.perf_counter()
print("Time taken by counter: ", end_time - start_time, "seconds")
What a beautiful way of explaining stuff!🙌🙌learnt a lot! Thankss
thanks for powerful content
Hi Bro! I have been following this course as I teach myself coding and it has been a HUGE help! I did have question about the "time.perf_counter()" call. For whatever reason whenever I run this it returns with something like this : "finished in: 584461.4056658 seconds" when in reality it took about 11 seconds to finish. I am not sure why this is occurring as I have typed out everything that same you have. Thanks again for all the videos, they have been fantastic!
same here
THIS!^^^^^ please explain...
Hello. I've been watching the full python course and I had this same problem. I don't know if you already got a solution or even if you just stopped thinking about it. I created a variable in the beginning of the function main and one in the end (of that same function), both associated to a time.perf_counter() method. In the end i printed the difference between the last perf_counter() and the first one and now it looks like it works. I'm not sure if this is the right approach but I tried with 8 cores and, in my case, the result is between 7 and 9 seconds.
uppp
@@henriquemanuelcordeirorodr2523 Bro thank you so much this was an absolute pain for a while. It seems not known or something on the rest of the internet lol.
Hey you, Yes! I am talking to you, it's a nice video
❤
amazing
You're awesome
your tutorials are excellent....thanks Bro...!
Thank you very much. It was a great explanation.
bro is soooper cool!!
legend!!!!!😍
Nice video BROOOO
great !!
finally!!! i have got some clear understandings.
Excelent video bro, leaving my comment.
I love you brocode
LOve u
thx 4 vid bro !
thanks bro
Hi, is correct? Multiprocessing is SAME CALCATION parralel. Multithread is Run any tasks in same time on all threads prcoessor
thanks
Ty bro
Wow!
Thank you!
Thank you😄
thanks bro! really helped
Thanks! great content and explanation! Can you help with instruction how to combine concurrency (such as asyncio or asyncioscheduler with multiprocessing)? Example, I want 2 processes dedicated to computing, and the other 2 dedicated for I/O tasks.
nice video Bro!
In this program, to count the numbers, can we also use multi threading? Why is multi processing is over multi threading when counting?
I understand that Python multi-processing and multi-threading can accelerate running independent tasks. However, If I have 10 tasks sequentially and each one's input rely on the previous one's output, is it still possible to accelerate using parallel computing or parallel processing? Any perspective from software or hardware will be appreciated!
It's possible, but it will not provide a significant performance boost
Was this done on Intel or amd cpu
meow~! uwu
Hi Bro
def main():
print("cpu count:", cpu_count())
If I use:
a = Process(target=counter(500000000))
b = Process(target=counter(500000000))
I get:
cpu count: 8
processing...
Done!
finished in: 43 seconds
instead of:
a = Process(target=counter, args=(500000000,))
b = Process(target=counter, args=(500000000,))
I get the same results but
cpu count: 8
processing...
Done!
finished in: 22 seconds
It seem I get the same results but the time comsuption is so much higher .... Any explanation.... Thanks
doesnt work for me at all. ImportError: cannot import name 'Process' from partially initialized module 'multiprocessing' (most likely due to a circular import) it looks like those functions doesn't exist in library or sth ? also already in this part "from multiprocessing import Process, cpu_count" it cant find reference to Process, cpu_count...any ideas what's going on?
solved : i named the whole file the same way (multiprocessing) after changing interpreter suddenly found what was needed.
: )
@everyone I have a question. How does it come, that my time.perf_counter() does not give out the time, since the programm started. If I want to achieve that, I have to type in x = time.perf_counter() at the start of the programm and subtract the perf_counter() from the end by x and then I get the right time. Sorry if my english is not very good. Hope someone can help me with that problem
I have the same problem
Hi bro i need some help here on my project on java
I have 16 core processor so I can create 16 processes at once ☺
Hey bro, when the complete task was divided into two processes, why was the time taken not halved?
and, are there any disadvantages of processes that threads doesn't have? You advised to use threads for io bound operations in a previous video...
Thanks!
I don't exactly know the full reason, but like Bro Code mentioned: every time you create a process there is a significant overhead in terms of time. Which is part of the reason why it's not exactly half.
maybe processor boosting the 1 core higher, more than it could with 2 cores or just python not being very efficient
im on a beast of a pc so 8 of em was 8 seconds, 150 000 000 per second
ta
Hey Bro, my code is giving me several errors... I'm not sure what to do, could you help me out?
a
E
hey bro, in my pc perf_counter is returning an unusually large number 20000 seconds, why?? and how to fix it??
I think it is using another time as its reference. I had similar issue. I was able to fix by defining t1 = time.perf_counter() at beginning, t2 = time.perf_counter() at end, then printing t2 - t1 seconds.
finished in: 21190.5506864 seconds
what's wrong my cpu
Don't know man, mine says finished in 71858.8663355 seconds, even though it took like 8 seconds. Why does it say that?
@@lucamassimosantilli8533 Yeah same. I look at codes again and again, maybe missed some code or typed wrong code that changed the type of "sec". But nothing. Maybe someone sees and helps some other time. Cheers.
add this to the start : start = time.perf_counter()
and add this to the print function : time.perf_counter()-start
basically starting a timer and then subtracting it
@@raedshaher5186 Thank you!
@@raedshaher5186 Thanks man I've had the same issue ;)
thanks
thanks bro