diff --git a/contrib/onelab/python/OnelabClient.py b/contrib/onelab/python/OnelabClient.py
index 8bfe3d240d0ccde3f4a6dd243e457bcbfc1f1fc7..771f165b8cc656020fe72f71e29d0fd1c80fbba2 100755
--- a/contrib/onelab/python/OnelabClient.py
+++ b/contrib/onelab/python/OnelabClient.py
@@ -78,7 +78,8 @@ class client :
   _GMSH_CONNECT = 27
   _GMSH_OLPARSE = 28
   _GMSH_PARAM_NOT_FOUND = 29
-    
+  _GMSH_OPTION_1 = 100
+  
   def _receive(self) :
     def buffered_receive(l) :
       msg = b''
@@ -97,8 +98,13 @@ class client :
 
   def _send(self, t, msg) :
     m = msg.encode('utf-8')
-    if self.socket.send(struct.pack('ii%is' %len(m), t, len(m), m)) == 0 :
-      RuntimeError('onelab socket closed')
+    try:
+      if self.socket.send(struct.pack('ii%is' %len(m), t, len(m), m)) == 0 :
+        RuntimeError('onelab socket closed')
+    except socket.error:
+      self.socket.close()
+      self._createSocket()
+      self.socket.send(struct.pack('ii%is' %len(m), t, len(m), m))
 
   def _def_parameter(self, param) :
     if not self.socket :
@@ -145,17 +151,23 @@ class client :
   def sub_client(self, name, command):
     print 'Defining the subclient ' + name
     msg = [name, command]
-    ## msg.append(name + '\0')
-    ## msg.append(command + '\0')
     if not self.socket :
       return
     self._send(self._GMSH_CONNECT, '\0'.join(msg))
-    (t, msg) = self._receive()
-    print ("python receive : ", t, msg)
-    if t == self._GMSH_CONNECT and msg :
-      print "python launch : "+ command + " -onelab " + name + " " + msg
-      os.system(command + " -onelab " + name + " " + msg)
-
+    ## (t, msg) = self._receive()
+    ## print ("python receive : ", t, msg)
+    ## if t == self._GMSH_CONNECT and msg :
+    ##   print "The client %s is now connected" %(msg)
+    ##   print "python launch : "+ command + " -onelab " + name + " " + msg
+    ##   os.system(command + " -onelab " + name + " " + msg)
+
+  def wait_on_subclient(self, name):
+    if not self.socket :
+      return
+    (t, msg) = self._receive() 
+    if t == self._GMSH_OPTION_1 :
+      print 'Client <%s> done, proceeding with the script...' %(name)
+      
   def merge_file(self, filename) :
     if not self.socket :
       return
@@ -170,19 +182,26 @@ class client :
       filename = os.getcwd() + "/" + filename;
     self._send(self._GMSH_OLPARSE, filename)
 
+  def _createSocket(self) :
+    addr = self.addr
+    if '/' in addr or '\\' in addr or ':' not in addr :
+      self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+    else :
+      self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    self.socket.connect(addr)
+    #self.socket.setblocking(1)
+    #self.socket.settimeout(5.0)
+  
   def __init__(self):
     self.socket = None
     self.name = ""
+    self.addr = ""
     for i, v in enumerate(sys.argv) :
       if v == '-onelab':
         self.name = sys.argv[i + 1]
-        addr = sys.argv[2]
-        if '/' in addr or '\\' in addr or ':' not in addr :
-          self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-        else :
-          self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self.socket.connect(sys.argv[i + 2])
-        self._send(self._GMSH_START, str(os.getpid))
+        self.addr = sys.argv[i + 2]
+        self._createSocket()
+        self._send(self._GMSH_START, str(os.getpid()))
     self.action = self.get_string('python/Action')
     if self.action == "initialize": exit(0)
   
@@ -190,3 +209,4 @@ class client :
     if self.socket :
       self._send(self._GMSH_STOP, 'Goodbye!')
       self.socket.close()
+      print 'Destructor called for %s' %(self.name)
diff --git a/contrib/onelab/python/sub.py b/contrib/onelab/python/sub.py
new file mode 100755
index 0000000000000000000000000000000000000000..c432a9231916ce7e1e2c1a393c3d103baf3cdbf5
--- /dev/null
+++ b/contrib/onelab/python/sub.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+#coding=utf-8
+
+
+import OnelabClient
+
+oc = OnelabClient.client()
+
+A = oc.get_number('A')
+B = oc.def_number('Group/B', 20)
+
+print 'A= %f B = %f' %(A, B)
+
+print('Action=%s' %(oc.get_string('python/Action')))
diff --git a/contrib/onelab/python/test.py b/contrib/onelab/python/test.py
index 311f66846cb736cc8daae35b098c539b7697c2ba..5a17ae96b180ef166a2a9ac1cbff0b3fd95171f0 100755
--- a/contrib/onelab/python/test.py
+++ b/contrib/onelab/python/test.py
@@ -7,30 +7,32 @@ oc = OnelabClient.client()
 #name and default value are required
 A = oc.def_number('A', 10)
 #other attributes are optionals
-B = oc.def_number('Group/B', 0, min = -10, max = 10, step = 1)
-C = oc.def_number('Group/C', 2, choices = [0, 1, 2, 3], attributes={'Highlight':'Pink'})
-D = oc.def_number('Group/D', 2, labels = {0:'zero', 1:'un', 2:'deux', 3:'trois'}, attributes={'Highlight':'Blue'})
-#utf-8 are allowed everywhere (should be prefixed by 'u' in python 2, not required in python 3)
-#Omega = oc.get_string(u'Ω', u'∫(∂φ/∂α)³dx', help=u'ask someone@universe.org', choices = ['oui', 'non', u'peut-être'])
+#B = oc.def_number('Group/B', 0, min = -10, max = 10, step = 1)
+
 
 modelName = 'coin'
 
 oc.merge_file(modelName + '.geo')
 
-#print('Action=%s pour %s' %(oc.action,'python'))
 print('Action=%s' %(oc.get_string('python/Action')))
 
 oc.sub_client('gmsh', 'gmsh ' + modelName + '.geo -2')
 
 oc.merge_file(modelName + '.msh')
 
+oc.sub_client('subclient', 'sub.py')
+print 'script is waiting until subclient is done'
+oc.wait_on_subclient('subclient');
+
+C = oc.def_number('Group/C', 2, choices = [0, 1, 2, 3], attributes={'Highlight':'Pink'})
+D = oc.def_number('Group/D', 2, labels = {0:'zero', 1:'un', 2:'deux', 3:'trois'}, attributes={'Highlight':'Blue'})
+#utf-8 are allowed everywhere (should be prefixed by 'u' in python 2,
+#not required in python 3)
+#Omega = oc.get_string(u'Ω', u'∫(∂φ/∂α)³dx', help=u'ask someone@universe.org',
+#choices = ['oui', 'non', u'peut-être'])
+
 oc.convert_olfile(modelName + '.txt')
 
-oc.sub_client('python', 'python ' + modelName + '.py')
 
 if oc.action != 'compute' :
   exit(0)
-
-## insert here the client's script
-  
-exit(0)