[Tutor] question about importing threads

Kent Johnson kent37 at tds.net
Sat Dec 30 15:59:01 CET 2006


shawn bright wrote:
> Hello there all.
> i have an app that has grown to about 4000 lines. It uses 6 threads and 
> a GTK2 GUI.
> i was wondering if i could split it into seperate files that i could 
> import. Each thread is a class.

That should be fine.

> i did not think that this would be a problem, but some of the threads 
> pass information to views and buffers.

How do the threads find out about the views and buffers? If they are 
global objects then you will have a problem. If they are passed to the 
threads as parameters then it should be fine.

> If i had a thread outside of the main file, could i pass a gtk object to 
> it so that it could write to it when it needed too?

Yes.

> and one last thing. If i did this, would i be able to only import the 
> class when i started the thread, and then re-import it if i started the 
> thread later . If so, this would allow me to work on a thread without 
> having to restart the main program, and i could let the other threads 
> keep running. As i find bugs, i could squash them without loosing any 
> functionality of the other threads. Then if i wanted to stop or restart 
> a thread by clicking a button, i could just re-import the class.
> 
> is this ok ?

You can use reload() to update a module that has been changed. You will 
also have to recreate any objects that were created from classes in the 
module so they become instances of the modified module. You might be 
interested in this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164

Kent

> 
> thanks
> shawn
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list