changeset 227:1b775632cbd9

Third attempt to work around unwarranted ERROR_ACCESS_DENIED on Windows
author Oleg Oshmyan <chortos@inbox.lv>
date Wed, 06 Jun 2012 20:22:18 +0100
parents 2cdd966bc5fb (current diff) ebb35960b5bc (diff)
children 928a6091454c
files
diffstat 1 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/upreckon/win32.py	Fri May 04 17:17:30 2012 +0100
+++ b/upreckon/win32.py	Wed Jun 06 20:22:18 2012 +0100
@@ -1,4 +1,4 @@
-# Copyright (c) 2010-2011 Chortos-2 <chortos@inbox.lv>
+# Copyright (c) 2010-2012 Chortos-2 <chortos@inbox.lv>
 
 from __future__ import division, with_statement
 
@@ -146,6 +146,7 @@
 	__del__ = Close
 
 CHAR = c_char
+CREATE_BREAKAWAY_FROM_JOB = 0x01000000
 INVALID_HANDLE_VALUE = HANDLE(-1).value
 LPDWORD = POINTER(DWORD)
 LPFILETIME = POINTER(FILETIME)
@@ -472,19 +473,27 @@
 		ProcessMemoryLimit=ceil((case.maxmemory or 0)*1048576),
 	)
 	SetInformationJobObject(job, JobObjectExtendedLimitInformation, limits)
+	kwargs['creationflags'] = kwargs.get('creationflags', 0) | CREATE_BREAKAWAY_FROM_JOB
 	try:
 		case.process = Popen(*args, **kwargs)
 	except OSError:
 		raise CannotStartTestee(sys.exc_info()[1])
 	case.time_started = clock()
-	try:
-		AssignProcessToJobObject(job, case.process._handle)
-	except WindowsError:
+	while True:
 		try:
-			if case.process.poll() is None:
-				raise CannotStartTestee(sys.exc_info()[1])
+			AssignProcessToJobObject(job, case.process._handle)
 		except WindowsError:
-			raise CannotStartTestee(sys.exc_info()[1])
+			e = sys.exc_info()[1]
+			try:
+				if case.process.poll() is not None:
+					break
+			except WindowsError:
+				e = sys.exc_info()[1]
+			if e.winerror != ERROR_ACCESS_DENIED:
+				raise CannotStartTestee(e)
+			time.sleep(0)
+		else:
+			break
 	if not console_input:
 		if case.maxwalltime:
 			if (WaitForSingleObject(case.process._handle, case.maxwalltime) !=