瀏覽代碼

[python] Added missing python.lib.Sys.version_info. Catch OSError in Process.close when using python < 3.3.

Andy Li 9 年之前
父節點
當前提交
00eec55401
共有 2 個文件被更改,包括 15 次插入6 次删除
  1. 13 5
      std/python/_std/sys/io/Process.hx
  2. 2 1
      std/python/lib/Sys.hx

+ 13 - 5
std/python/_std/sys/io/Process.hx

@@ -52,11 +52,19 @@ class Process {
 		return p.wait();
 	}
 	public function close() : Void {
-		try {
-			p.terminate();
-		} catch (e:python.Exceptions.ProcessLookupError) {
-			// it has already terminated 
-		}
+		var ver = python.lib.Sys.version_info;
+		if (ver[0] > 3 || (ver[0] == 3 && ver[1] >= 3)) // >= 3.3
+			try {
+				p.terminate();
+			} catch (e:python.Exceptions.ProcessLookupError) {
+				// it has already terminated 
+			}
+		else
+			try {
+				p.terminate();
+			} catch (e:python.Exceptions.OSError) {
+				// it has already terminated 
+			}
 	}
 	public function kill() : Void {
 		p.kill();

+ 2 - 1
std/python/lib/Sys.hx

@@ -25,7 +25,7 @@ import python.Exceptions.BaseException;
 import python.lib.io.FileIO;
 import python.lib.io.RawIOBase;
 import python.lib.io.TextIOBase;
-import python.Tuple.Tuple3;
+import python.Tuple;
 
 
 extern class TB {}
@@ -53,4 +53,5 @@ extern class Sys {
 
 	public static function exc_info<T:BaseException>():Tuple3<Class<T>, T, TB>;
 
+	public static var version_info:Tuple5<Int,Int,Int,String,Int>;
 }