mmkw43
Posts: 554
Joined: Tue Dec 24, 2013 6:18 pm

PI 2 dual core and Python?

Wed Jun 10, 2015 1:44 pm

Is there anything new that is a programming advantage with the new dual core PI 2? What I mean is, I know that having a dual core processor means that you can actually do multiple things at once but I've found that with the combination of Python and Tkinter working together, I can't really do background threads like I could with VB.net

For example, right now (with a model B+) I have Python running a continuous loop sensing the GPIO ports and have Tkinter giving me GUI displays and all is working great but I'd like to add some audio alerts in the background and can't do it unless I completely pause the program.

Just wondering if the new PI 2 and maybe some enhanced code will change that. ? Thanks. Hope I'm making sense.

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: PI 2 dual core and Python?

Wed Jun 10, 2015 1:53 pm

Well you don't really need multi-threading for that.. but python does have threading (google "python threading").. but python won't use multiple processors.. though the multiprocessing module does.

PS it's got four cores by the way!
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

mmkw43
Posts: 554
Joined: Tue Dec 24, 2013 6:18 pm

Re: PI 2 dual core and Python?

Wed Jun 10, 2015 2:12 pm

Yes -- I know Python has threading and have written threads. I'd like to know how I can have background audio going when I have a nonstop loop sensing the GPIO inputs, tkinter giving me display info (which also has to loop -- root.mainloop() actually tkinter is more of a problem than python.

you say I don't need multi-threading but I've tried everything. In VB.net you can do many things at once.

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: PI 2 dual core and Python?

Wed Jun 10, 2015 2:40 pm

There are lots of ways of playing a sound and I'm not sure which is best with tkinter. I think it's built in to pygame quite well. The only thing I have used on the RPi is subprocess Popen to start mpg321 see https://github.com/pi3d/pi3d_demos/blob ... box.py#L67. That very explicitly starts a new process which might very well run on a different core.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

mmkw43
Posts: 554
Joined: Tue Dec 24, 2013 6:18 pm

Re: PI 2 dual core and Python?

Wed Jun 10, 2015 2:50 pm

thanks paddyg ! that's a new one on me -- will play with it. I'll get this figured out.

Return to “Python”