Friday, December 7, 2012

Mulithreading in 'Quickly', python RAD tool by canonical

I was doing my WiMixer application through Quickly tool by Canonical for developing application for Ubuntu/Linux. But when I had to do socket programming phase I can't start a threading inside the Quickly.

I was so frustrated and tried everything. After a while a help from Michael Hall in IRC chat of Quickly channel + thanks to this this post in askubuntu. I found out how to do it. I thought it might be valubale to some if I shared it in here with you.

What you have to do is simple. At the very beginning of the python file which your thread will fire, include these lines.

import threading
from gi.repository import GObject
GObject.threads_init()

and then as usually done in python just start the thready as

listener_thread = threading.Thread(target=function_name)
listener_thread.start()

We want to initialize the GObject as quickly uses gi repository to import GUI from the glade file. So it initially starts in a separate thread at beginning of the loading of GUI. So the next threads we start won't be started until GUI (gobject thread) is closed.

I'll conclude this post as my usual statement. If you are using open source, you will always have a way to solve your problems or you might find a friend that will help you. :-)

No comments: