For starters I'm a C, C++ programmer mostly, 35 years in it.
For the most part python is fairly easy to use.
I recently posted this up on
So I wanted to add multiprocessing to it. Multi-proccessing not multi-threading. There is a difference and those of you who know enough about the GIL know why that is.
I figured well shit how hard can it be its easy enough in C and C++.
It's actually more of a pain in the ass in python. It doesn't help some child decided to use terms like pickling and dill instead of terms like package and serialize. Just kidding about the child part. haha. But seriously it doesn't help.
You can find countless tutorials and explanations for handling a simple method. Most of which don't show any arguments passed to the method.
Try and find one that shows an array containing classes which you need to update via a member function.
C, C++ are quite a bit easier. Hell even on windows back 20+ years ago it was easier than this.
The class I am trying to do this with is posted below.
The method is that needs to be ran is the update method that is a member of it.
There is an array of these objects that needs to be done.
Even python's own documentation doesn't cover it. There are some that get close but fail to cover passing variables to the function or packaging them with it.
I'll probably stick this up on stack exchange as well.
I was seriously not expecting it to be this hard to do when it came to python. Yea, I knew multithreading would be a waste but ouch.
If you wonder if it works well I attached the performance profile.
See it for yourself.
The nested loops only makes a difference of 6 microseconds. Microseconds not milliseconds.
The greatest amount of time isn't even in areas I can control. It's in the pygame "blit" function.
If you want you can replace the code at the bottom of game.py with the following and profile it yourself.
Not like you need to take my word on it.
For the most part python is fairly easy to use.
I recently posted this up on
You must be registered to see the links
on github. It's single threaded but performs ok. It's a lot slower than the C++ version I created and vastly slower than the multi-threaded version.So I wanted to add multiprocessing to it. Multi-proccessing not multi-threading. There is a difference and those of you who know enough about the GIL know why that is.
I figured well shit how hard can it be its easy enough in C and C++.
It's actually more of a pain in the ass in python. It doesn't help some child decided to use terms like pickling and dill instead of terms like package and serialize. Just kidding about the child part. haha. But seriously it doesn't help.
You can find countless tutorials and explanations for handling a simple method. Most of which don't show any arguments passed to the method.
Try and find one that shows an array containing classes which you need to update via a member function.
C, C++ are quite a bit easier. Hell even on windows back 20+ years ago it was easier than this.
The class I am trying to do this with is posted below.
The method is that needs to be ran is the update method that is a member of it.
There is an array of these objects that needs to be done.
You don't have permission to view the spoiler content.
Log in or register now.
Even python's own documentation doesn't cover it. There are some that get close but fail to cover passing variables to the function or packaging them with it.
I'll probably stick this up on stack exchange as well.
I was seriously not expecting it to be this hard to do when it came to python. Yea, I knew multithreading would be a waste but ouch.
If you wonder if it works well I attached the performance profile.
See it for yourself.
The nested loops only makes a difference of 6 microseconds. Microseconds not milliseconds.
The greatest amount of time isn't even in areas I can control. It's in the pygame "blit" function.
If you want you can replace the code at the bottom of game.py with the following and profile it yourself.
Not like you need to take my word on it.
Python:
#if __name__ == "__main__":
# main()
import cProfile
cProfile.run('main()',"output.dat")
import pstats
from pstats import SortKey
with open("output_time.txt","w") as f:
p = pstats.Stats("output.dat",stream=f)
p.sort_stats("time").print_stats()
with open("output_calls.txt","w") as f:
p = pstats.Stats("output.dat",stream=f)
p.sort_stats("calls").print_stats()
Last edited: