Is my thread safe from premature garbage collection?

2005-09-01 Thread NutJob
Hello all,

I'm aware that in Python an object is cleared for garbage collection as
soon as the last reference to it disappears. Normally this is fine.
However, in my current project I'm creating a bunch of threads which
are supposed to run until they've completed their run() method, and I'm
worried that if I do not keep references to these thread objects
around, the GC might happily delete them (and thereby kill my thread
routines maybe?) while they're not done yet. Is this fear justified? Or
is the Python GC smart enough to leave thread objects alone until their
run() methods have finished?

If not, I do have a workaround, but it is a bit clumsy IMO. Basically I
would just keep a list into which each thread object enters a reference
to itself on creation. This way I'd ensure that I have a reference to
the thread to prevent the GC from killing it. Then, when a thread is
about to finish its run() method, the thread finds and removes that
reference to itself from my list of thread references.

Anyway, if anyone could make a definite statement on whether threads
are safe from unwanted garbage collection, that'd be really great.
Thanks in advance for any helpful replies!

Cheers,

antred

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Well, Python is hard to learn...

2005-09-01 Thread NutJob
Well, I reckon it all depends on how much experience you have with
programming languages in general. If you're completely new to
programming it's probably going to take a while to get to grips with it
all, regardless of which language you're picking up, although I'd wager
that Python is still one of the most intuitive and easiest to learn
languages around. Personally I learnt to code in C++ Python, and Perl
with a little bit of Java, Tcl and C# thrown in there as well and I
like Python and C++ the most.
Just be patient, mate, you'll get the hang of it before long.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is my thread safe from premature garbage collection?

2005-09-01 Thread NutJob
Splendid! =) Thanks guys!

-- 
http://mail.python.org/mailman/listinfo/python-list


Creating custom event in WxPython

2005-09-01 Thread NutJob
Hello,

I'm faced with the following problem: I have a (secondary) thread that
monitors a socket for incoming message traffic using the
select.select() function.

Besides that I also have the main thread of my WxPython application. So
far so good.

Now when my socket thread detects an incoming message, I need my main
thread to interpret the message and react to it by updating the GUI.
IMO the best way to achieve this is by having my socket thread send a
custom event to my application's event loop for the main thread to
process. However, I'm at a total loss as far as creating custom events
is concerned. The WxWindows documentation isn't very helpful on this
either.
I think I need to derive my own event class from the wxEvent class, but
I have no idea HOW (i.e. what methods do I need to override, etc.) Can
anyone help me?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is my thread safe from premature garbage collection?

2005-09-08 Thread NutJob
Good point there. Sorry, I should have thought of that myself really,
but well, I guess I'm having my senior moments a bit early. :P

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating custom event in WxPython

2005-09-08 Thread NutJob
Cool, thanks a bunch!

-- 
http://mail.python.org/mailman/listinfo/python-list