You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by st...@apache.org on 2012/06/11 21:52:16 UTC

svn commit: r1349039 - in /incubator/tashi/trunk/src/tashi: util.py utils/timeout.py

Author: stroucki
Date: Mon Jun 11 21:52:15 2012
New Revision: 1349039

URL: http://svn.apache.org/viewvc?rev=1349039&view=rev
Log:
util: name threads
timeout: if exception occurs in remote call, send it back as a result

Modified:
    incubator/tashi/trunk/src/tashi/util.py
    incubator/tashi/trunk/src/tashi/utils/timeout.py

Modified: incubator/tashi/trunk/src/tashi/util.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/util.py?rev=1349039&r1=1349038&r2=1349039&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/util.py (original)
+++ incubator/tashi/trunk/src/tashi/util.py Mon Jun 11 21:52:15 2012
@@ -262,7 +262,7 @@ def debugConsole(globalDict):
 		os._exit(0)
 
 	if (os.getenv("DEBUG", "0") == "1"):
-		threading.Thread(target=lambda: realDebugConsole(globalDict)).start()
+		threading.Thread(name="debugConsole", target=lambda: realDebugConsole(globalDict)).start()
 
 def stringPartition(s, field):
 	index = s.find(field)
@@ -324,10 +324,11 @@ class Connection:
 		if self.connection is None:
 			self.__connect()
 
+		threadname = "%s:%s" (self.host, self.port)
 		# XXXstroucki: Use 10 second timeout, ok?
 		# XXXstroucki: does this fn touch the network?
 		t = TimeoutThread(getattr, (self.connection, name, None))
-		threading.Thread(target=t.run).start()
+		threading.Thread(name=threadname, target=t.run).start()
 
 		try:
 			remotefn = t.wait(timeout=10)
@@ -339,7 +340,7 @@ class Connection:
 			if callable(remotefn):
 				# XXXstroucki: Use 10 second timeout, ok?
 				t = TimeoutThread(remotefn, args, kwargs)
-				threading.Thread(target=t.run).start()
+				threading.Thread(name=threadname, target=t.run).start()
 				returns = t.wait(timeout=10.0)
 
 			else:

Modified: incubator/tashi/trunk/src/tashi/utils/timeout.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/utils/timeout.py?rev=1349039&r1=1349038&r2=1349039&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/utils/timeout.py (original)
+++ incubator/tashi/trunk/src/tashi/utils/timeout.py Mon Jun 11 21:52:15 2012
@@ -53,7 +53,11 @@ class TimeoutThread:
 			raise TimeoutException("function %s timed out after %f seconds" % (str(self.function), timeout))
 
 	def run(self):
-		rval = self.function(*self.args, **self.kwargs)
+		try:
+			rval = self.function(*self.args, **self.kwargs)
+		except Exception, e:
+			rval = e
+
 		self.cv.acquire()
 		self.finished = True
 		self.rval	 = rval