![]() |
Re: Multitasking and GTK with python
Quote:
|
Re: Multitasking and GTK with python
Don't forget to initialize threads with gobject or else (I suspect) it holds on to the GIL while mainloop is processing and doesn't allowing other threads to run.
I've been using Code:
gtk.gdk.threads_init()Code:
@contextlib.contextmanagerCode:
with gtk_lock():https://garage.maemo.org/scm/?group_id=657 You can also queue tasks to run in the UI thread from your worker thread using idle_add. I use the following helper Code:
def async(func):https://garage.maemo.org/scm/?group_id=1078 |
Re: Multitasking and GTK with python
Code:
import pygtk |
Re: Multitasking and GTK with python
Also, if you use threads with gtk, you need to call
gtk.gdk.threads_init(). pygtk (binding for python and gtk) holds the GIL (which is kind of a global lock for the process) unless threads_init() is called. Try adding this line in the __init__. |
Re: Multitasking and GTK with python
i posted the full code please could you tell me what should i do about it?
edit: yeaa great it worked it worked THANK YOU ALL :d:d |
Re: Multitasking and GTK with python
Quote:
epage mentioned that as well but also extended this to how to handle the GUI itself from within child-threads (also called 'worker threads'), and suggested an alternative - give the gtk to handle your worker threads while it's available using the add_idle example he attached. An advice - If it's your first work with treads, you might want to know more about threads in general and threads in python before diving into gtk's way for handling threads. |
Re: Multitasking and GTK with python
it is great im very excited it worked after adding gtk.gdk.threads_init()
thank you all for all helps im really appreciated |
Re: Multitasking and GTK with python
Just use gobject.io_add_watch to be notified when there is data to read and spare yourself the ordeal of using threads.
http://faq.pygtk.org/index.py?req=sh...=faq20.016.htp def handle_data(source, condition): __data = source.recv(1024) __if len(data) > 0: ____self.entrybox.set_text(self.entrybox.get_text( ) + data) ____# or maybe just self.entrybox.props.text += data ____#print data ____return True # call me again if something happens __else: # end of file ____return False # stop calling me sock=BluetoothSocket(RFCOMM) #sock.settimeout(15) # ? sock.connect(('00:1F:00:B5:3A:45',5)) gobject.io_add_watch(sock, gobject.IO_IN, handle_data) What happens is that your GUI program ALSO watches your socket and should something arrive, it will call "handle_data" which then reads the chunk that arrived (that is fast). After that, your GUI program resumes. Note that threads didn't enter the picture anywhere (not in the GTK library either). |
Re: Multitasking and GTK with python
i made a couple of apps that im using myself
one is for texting over n95 8gb and received text messages via n95 8gb |
| All times are GMT. The time now is 22:18. |
vBulletin® Version 3.8.8