Index: /trunk/SophyaLib/SysTools/commander.cc
===================================================================
--- /trunk/SophyaLib/SysTools/commander.cc	(revision 2942)
+++ /trunk/SophyaLib/SysTools/commander.cc	(revision 2943)
@@ -6,4 +6,5 @@
 #include <ctype.h>
 #include <math.h>
+#include <signal.h>
 
 #include "strutil.h"
@@ -341,4 +342,5 @@
   \ingroup SysTools 
   Class for internal use by class Commander for command execution in separate threads.
+  The command execution is carried in method run() which has its own exception handling bloc.
 */
 class CommandExeThr :  public ZThread  {
@@ -377,5 +379,22 @@
 void CommandExeThr::run()
 {
-  int rc = _cmdex->Execute(_keyw, _args, _toks);
+  int rc = 0;
+  try {
+    rc = _cmdex->Execute(_keyw, _args, _toks);
+  }
+  catch (PThrowable& exc) {
+    cout << "CommandExeThr::run() Catched Exception Msg()= " 
+	 << exc.Msg() << endl;
+    rc = -77;
+  }
+  catch (std::exception& sex) {
+    cout << "CommandExeThr::run() Catched std::exception what()= " 
+	 << sex.what() << endl;
+    rc = -78;
+  }
+  catch (...) {
+    cout << "CommandExeThr::run() Catched unknown (...) exception " << endl; 
+    rc = -79;
+  }
   _fgdone = true;
   setRC(rc);
@@ -402,4 +421,5 @@
   - Simple and vector variables
   - Script definition 
+  - Command execution in separate threads
   - Dynamic Load 
 
@@ -492,5 +512,5 @@
 usage += "  > thrlist       # List of command execution threads (& as the last character) \n";
 usage += "  > clearthrlist  # Removes finished threads from the list  \n";
-usage += "  > cancelthr Id  # Cancel a given thread (ThrId=id)  \n";
+usage += "  > stopthr Id    # Try to stop a given thread (ThrId=id) sending SIGUSR1 \n";
 usage += "  > waitthr       # Waits until all active threads have finished (join()) \n";
 usage += "  > exec filename # Execute commands from file \n";
@@ -704,5 +724,5 @@
 
 /* --Methode-- */
-//! Select an interpreter by its name. The corresponding Interpret method is then called
+//! Select an interpreter by its name as the current interpreter. 
 void Commander::SelInterpreter(string& name)
 {
@@ -1081,4 +1101,5 @@
 }
 
+//! Can be called asynchronously (from a separate thread) to break (halt) execution (in loops, scripts ...) 
 void  Commander::StopExecution()
 {
@@ -1857,8 +1878,8 @@
   return(0);
 }
-else if (kw == "cancelthr") {
-  if (tokens.size() < 1) { cout << "Commander::Interpret() Usage: cancelthr thrid" << endl;  return(0); }
+else if (kw == "stopthr") {
+  if (tokens.size() < 1) { cout << "Commander::Interpret() Usage: stopthr thrid" << endl;  return(0); }
   uint_8  id = atol(tokens[0].c_str());
-  CancelThr(id);
+  StopThr(id);
   return (0);
 }
@@ -1938,11 +1959,12 @@
 	CmdThrExeList.push_back(thr);
 	cout << " Commander::ExecuteCommand() : Thread execution of command " << keyw << endl;
-	thr->start();    
+	thr->start();
+	if (CmdThrExeList.size() > 5)  CleanThrList();
 	rc = 0;
       }
-      else rc = (*it).second.cex->Execute(keyw, args, toks);
+      else  rc = (*it).second.cex->Execute(keyw, args, toks);
     }
     else cout << "Dont know how to execute " << keyw << " ? " << endl;
-    }
+  }
   return(rc);
 }
@@ -2015,15 +2037,15 @@
 }
 /* --Methode-- */
-void Commander::CancelThr(uint_8 id)
+void Commander::StopThr(uint_8 id)
 {
   for(list<CommandExeThr *>::iterator tit = CmdThrExeList.begin(); 
       tit != CmdThrExeList.end(); tit++) {
-    if ((*tit)->Id() == id) { 
-      (*tit)->cancel();  
-      cout << "Commander::CancelThr()  Thread Id= " << id << " cancelled" << endl;
+    if ( ((*tit)->Id() == id) && !((*tit)->IfDone()) ) { 
+      (*tit)->kill(SIGUSR1);  
+      cout << "Commander::StopThr()  Send signal SIGUSR1 to Thread Id= " << id << endl;
       return;
     }
   }
-  cout << "Commander::CancelThr()/Error: No thread with Id= " << id << endl;
+  cout << "Commander::StopThr()/Error: No active thread with Id= " << id << endl;
 }
 
@@ -2143,5 +2165,23 @@
 
 /* --Methode-- */
-//! Produces a LaTeX file containing the registered command helps
+/*!
+  \brief Produces a LaTeX file containing the registered command helps
+  The file \b fname is created and can be inserted into a LaTeX document
+  in order to produce the list of registered commands and corresponding description
+  texts.
+  The LaTeX file should contain the following definitions:
+\verbatim
+  \newcommand{\piacommand}[1]{
+    \framebox{\bf \Large #1 } \index{#1} % (Command) 
+  }
+
+  \newcommand{\piahelpitem}[1]{
+    \framebox{\bf \Large #1 } \index{#1} (Help item)
+  }
+
+  \newcommand{\myppageref}[1]{ (p. \pageref{#1} ) }
+
+\endverbatim
+*/
 void Commander::HelptoLaTeX(string const & fname)
 {
Index: /trunk/SophyaLib/SysTools/commander.h
===================================================================
--- /trunk/SophyaLib/SysTools/commander.h	(revision 2942)
+++ /trunk/SophyaLib/SysTools/commander.h	(revision 2943)
@@ -55,5 +55,5 @@
   //! command execution method for a command defined by keyword and its arguments.
   virtual int	Execute(string& keyw, vector<string>& args, string& toks)=0;
-  //! Return true if the command \b keyw is thread compatible
+  //! Return true if the command \b keyw is thread compatible (can be executed in a separate thread)
   virtual bool  IsThreadable(string const & keyw) { return false; }
 };
@@ -105,4 +105,5 @@
   virtual void 		HelptoLaTeX(string const & flnm);
 
+  //! return the current selected interpreter (default : this)
   inline  CmdInterpreter* CurrentInterpreter() { return(curcmdi); }
 
@@ -170,5 +171,5 @@
   //   Gestion des threads d'execution de commandes 
   void          ListThreads();
-  void          CancelThr(uint_8 thrid);
+  void          StopThr(uint_8 thrid);
   void          CleanThrList();
   void          WaitThreads();
Index: /trunk/SophyaLib/SysTools/zthread.cc
===================================================================
--- /trunk/SophyaLib/SysTools/zthread.cc	(revision 2942)
+++ /trunk/SophyaLib/SysTools/zthread.cc	(revision 2943)
@@ -6,4 +6,6 @@
 #include <stdlib.h>
 #include <stdio.h>
+#include <pthread.h>
+#include <signal.h>
 
 /*!
@@ -104,4 +106,15 @@
 }
 
+/*!
+  Calls the pthread_kill to deliver a signal to the corresponding thread
+*/
+void ZThread::kill(int sig)
+{
+  if (!_initok) throw ZThreadExc("ZThread::kill() - thread not started !");
+  int rc = pthread_kill(_thr, sig);
+  CheckSt(rc,"ZThread::kill() - Pb pthread_kill() ");  
+  setRC(-76);      
+}
+
 
 /*!
Index: /trunk/SophyaLib/SysTools/zthread.h
===================================================================
--- /trunk/SophyaLib/SysTools/zthread.h	(revision 2942)
+++ /trunk/SophyaLib/SysTools/zthread.h	(revision 2943)
@@ -31,5 +31,5 @@
   void		start();
   void		cancel();
-  inline void   stop() { cancel(); }
+  void          kill(int sig);
 
   void          join();
