Mercurial > cpython-lru_cache-weakref
annotate PC/VS9.0/kill_python.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 1085b0e475d8 |
| children |
| rev | line source |
|---|---|
|
77008
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
1 /* |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
2 * Helper program for killing lingering python[_d].exe processes before |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
3 * building, thus attempting to avoid build failures due to files being |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
4 * locked. |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
5 */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
6 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
7 #include <windows.h> |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
8 #include <wchar.h> |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
9 #include <tlhelp32.h> |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
11 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
12 #pragma comment(lib, "psapi") |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
13 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
14 #ifdef _DEBUG |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
15 #define PYTHON_EXE (L"python_d.exe") |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
16 #define PYTHON_EXE_LEN (12) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
17 #define KILL_PYTHON_EXE (L"kill_python_d.exe") |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
18 #define KILL_PYTHON_EXE_LEN (17) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
19 #else |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
20 #define PYTHON_EXE (L"python.exe") |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
21 #define PYTHON_EXE_LEN (10) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
22 #define KILL_PYTHON_EXE (L"kill_python.exe") |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
23 #define KILL_PYTHON_EXE_LEN (15) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
24 #endif |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
25 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
26 int |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
27 main(int argc, char **argv) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
28 { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
29 HANDLE hp, hsp, hsm; /* process, snapshot processes, snapshot modules */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
30 DWORD dac, our_pid; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
31 size_t len; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
32 wchar_t path[MAX_PATH+1]; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
33 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
34 MODULEENTRY32W me; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
35 PROCESSENTRY32W pe; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
36 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
37 me.dwSize = sizeof(MODULEENTRY32W); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
38 pe.dwSize = sizeof(PROCESSENTRY32W); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
39 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
40 memset(path, 0, MAX_PATH+1); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
41 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
42 our_pid = GetCurrentProcessId(); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
43 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
44 hsm = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, our_pid); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
45 if (hsm == INVALID_HANDLE_VALUE) { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
46 printf("CreateToolhelp32Snapshot[1] failed: %d\n", GetLastError()); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
47 return 1; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
48 } |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
49 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
50 if (!Module32FirstW(hsm, &me)) { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
51 printf("Module32FirstW[1] failed: %d\n", GetLastError()); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
52 CloseHandle(hsm); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
53 return 1; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
54 } |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
55 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
56 /* |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
57 * Enumerate over the modules for the current process in order to find |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
58 * kill_process[_d].exe, then take a note of the directory it lives in. |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
59 */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
60 do { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
61 if (_wcsnicmp(me.szModule, KILL_PYTHON_EXE, KILL_PYTHON_EXE_LEN)) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
62 continue; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
63 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
64 len = wcsnlen_s(me.szExePath, MAX_PATH) - KILL_PYTHON_EXE_LEN; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
65 wcsncpy_s(path, MAX_PATH+1, me.szExePath, len); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
66 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
67 break; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
68 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
69 } while (Module32NextW(hsm, &me)); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
70 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
71 CloseHandle(hsm); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
72 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
73 if (path == NULL) { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
74 printf("failed to discern directory of running process\n"); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
75 return 1; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
76 } |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
77 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
78 /* |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
79 * Take a snapshot of system processes. Enumerate over the snapshot, |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
80 * looking for python processes. When we find one, verify it lives |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
81 * in the same directory we live in. If it does, kill it. If we're |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
82 * unable to kill it, treat this as a fatal error and return 1. |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
83 * |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
84 * The rationale behind this is that we're called at the start of the |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
85 * build process on the basis that we'll take care of killing any |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
86 * running instances, such that the build won't encounter permission |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
87 * denied errors during linking. If we can't kill one of the processes, |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
88 * we can't provide this assurance, and the build shouldn't start. |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
89 */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
90 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
91 hsp = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
92 if (hsp == INVALID_HANDLE_VALUE) { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
93 printf("CreateToolhelp32Snapshot[2] failed: %d\n", GetLastError()); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
94 return 1; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
95 } |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
96 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
97 if (!Process32FirstW(hsp, &pe)) { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
98 printf("Process32FirstW failed: %d\n", GetLastError()); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
99 CloseHandle(hsp); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
100 return 1; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
101 } |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
102 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
103 dac = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
104 do { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
105 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
106 /* |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
107 * XXX TODO: if we really wanted to be fancy, we could check the |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
108 * modules for all processes (not just the python[_d].exe ones) |
|
79240
1085b0e475d8
Bump version to 3.4.0 alpha 0.
Georg Brandl <georg@python.org>
parents:
77008
diff
changeset
|
109 * and see if any of our DLLs are loaded (i.e. python34[_d].dll), |
|
77008
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
110 * as that would also inhibit our ability to rebuild the solution. |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
111 * Not worth loosing sleep over though; for now, a simple check |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
112 * for just the python executable should be sufficient. |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
113 */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
114 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
115 if (_wcsnicmp(pe.szExeFile, PYTHON_EXE, PYTHON_EXE_LEN)) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
116 /* This isn't a python process. */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
117 continue; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
118 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
119 /* It's a python process, so figure out which directory it's in... */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
120 hsm = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe.th32ProcessID); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
121 if (hsm == INVALID_HANDLE_VALUE) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
122 /* |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
123 * If our module snapshot fails (which will happen if we don't own |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
124 * the process), just ignore it and continue. (It seems different |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
125 * versions of Windows return different values for GetLastError() |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
126 * in this situation; it's easier to just ignore it and move on vs. |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
127 * stopping the build for what could be a false positive.) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
128 */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
129 continue; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
130 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
131 if (!Module32FirstW(hsm, &me)) { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
132 printf("Module32FirstW[2] failed: %d\n", GetLastError()); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
133 CloseHandle(hsp); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
134 CloseHandle(hsm); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
135 return 1; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
136 } |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
137 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
138 do { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
139 if (_wcsnicmp(me.szModule, PYTHON_EXE, PYTHON_EXE_LEN)) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
140 /* Wrong module, we're looking for python[_d].exe... */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
141 continue; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
142 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
143 if (_wcsnicmp(path, me.szExePath, len)) |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
144 /* Process doesn't live in our directory. */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
145 break; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
146 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
147 /* Python process residing in the right directory, kill it! */ |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
148 hp = OpenProcess(dac, FALSE, pe.th32ProcessID); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
149 if (!hp) { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
150 printf("OpenProcess failed: %d\n", GetLastError()); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
151 CloseHandle(hsp); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
152 CloseHandle(hsm); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
153 return 1; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
154 } |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
155 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
156 if (!TerminateProcess(hp, 1)) { |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
157 printf("TerminateProcess failed: %d\n", GetLastError()); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
158 CloseHandle(hsp); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
159 CloseHandle(hsm); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
160 CloseHandle(hp); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
161 return 1; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
162 } |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
163 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
164 CloseHandle(hp); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
165 break; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
166 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
167 } while (Module32NextW(hsm, &me)); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
168 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
169 CloseHandle(hsm); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
170 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
171 } while (Process32NextW(hsp, &pe)); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
172 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
173 CloseHandle(hsp); |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
174 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
175 return 0; |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
176 } |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
177 |
|
f6a207d86154
Issue 14813: Fix Visual Studio 2008 build after the move into the PC/VS9.0
Stefan Krah <skrah@bytereef.org>
parents:
diff
changeset
|
178 /* vi: set ts=8 sw=4 sts=4 expandtab */ |
