Killing subservient threads

2009-02-20 Thread jimzat
I am trying to create an app which will have a main window from which
the user will launch other (children) windows.

When I launch the child window I start a new thread which periodically
polls another device and updates the child window accordingly.  When I
dismiss the child window the "polling" thread stays alive and then
crashes with an exception when trying to write to the now defunct
child window.

How can I handle this?  I want to either 1) have the destructor for
the child window kill the spawned thread or 2) catch the exception
within the "polling" thread and see that the child window is gone and
then commit suicide.

I am an experienced embedded C programmer but have VERY little
experience with GUI programming and no experience in the Micro$oft
programming world.

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


Re: Killing subservient threads

2009-02-20 Thread jimzat
On Feb 20, 11:22 am, koranthala  wrote:
>
> thread.setDaemon(True)
> Makes it a daemon thread which means that interpreter will not stay
> alive if only that thread is alive.

My main window is used to launch multiple children and therefore when
one is dismissed the interpreter will remain active.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Killing subservient threads

2009-02-20 Thread jimzat
On Feb 20, 11:21 am, "Gabriel Genellina" 
wrote:
> 1) make the child window set a flag in the thread (let's say, t.terminate  
> = True). And make the polling thread check the flag periodically (you  
> possibly already have a loop there - just break the loop when you detect  
> that self.terminate became true)
>
> 2) catching an exception is as easy as enclosing the code in a try/except  
> block. And "commit suicide" is just "exit from the run() method".

Gabriel,

I am using the thread module and calling thread.start_new_thread
(...).  If I use t=thread.start_new_thread(...) and later set
t.terminate, I get "AttributeError: 'int' object has no attribute
'terminate'"

What is the proper way to do this?  I don't want to use globals as I
will have multiple child windows of various classes.


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


overloading for ladder logic

2008-11-07 Thread jimzat
I am trying to simulate the execution of some PLC ladder logic in
python.

I manually modified the rungs and executed this within python as a
proof of concept, but I'd like to be able to skip the  modification
step.  My thought was that this might be able to be completed via
overloading, but I am not sure if (or how) it could be done.

overloadings:
+ ==> OR
* ==> AND
/ ==> NOT

Example original code:
 A=/B+C*D
translates to:
A=not B or C and D

I tried
def __add__ (a,b):
return (a or b)

which gives me this:

>>> x=False
>>> y=True
>>> x+y
1
>>> x=True
>>> x+y
2

How can this be done?
--
http://mail.python.org/mailman/listinfo/python-list