Commits

Oleg Oshmyan  committed ebb3596

Third attempt to work around unwarranted ERROR_ACCESS_DENIED on Windows

  • Participants
  • Parent commits a78349b
  • Branches 2.03

Comments (0)

Files changed (1)

File upreckon/win32.py

-# Copyright (c) 2010-2011 Chortos-2 <chortos@inbox.lv>
+# Copyright (c) 2010-2012 Chortos-2 <chortos@inbox.lv>
 
 from __future__ import division, with_statement
 
 	__del__ = Close
 
 CHAR = c_char
+CREATE_BREAKAWAY_FROM_JOB = 0x01000000
 INVALID_HANDLE_VALUE = HANDLE(-1).value
 LPDWORD = POINTER(DWORD)
 LPFILETIME = POINTER(FILETIME)
 		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) !=