Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1:/tmp/cvs-serv12477
Modified Files:
PythonService.cpp
Log Message:
* Release the Python thread-state before calling into our servicemanager
entry point.
* indicate that 'Ctrl+C' is used to stop debugging a service.
* When debugging a service, get the messages from the .pyd rather than
the exe (as this is where they now live)
* Leave in an unused debugging macro.
* Add comments indicating that embedding the service name in the EXE
is deprecated (the new functions are better)
Index: PythonService.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PythonService.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** PythonService.cpp 16 Oct 2003 05:41:34 -0000 1.8
--- PythonService.cpp 25 Oct 2003 05:53:01 -0000 1.9
***************
*** 37,40 ****
--- 37,43 ----
BOOL bServiceDebug = FALSE;
+ // Globals
+ HINSTANCE g_hdll = 0; // remains zero in the exe stub.
+
static void ReportAPIError(DWORD msgCode, DWORD errCode = 0);
static void ReportPythonError(DWORD);
***************
*** 43,46 ****
--- 46,55 ----
#include "PythonServiceMessages.h"
+ // Useful for debugging problems that only show themselves when run under the SCM
+ #define LOG_TRACE_MESSAGE(msg) {\
+ LPTSTR lpszStrings[] = {_T(msg), NULL}; \
+ ReportError(MSG_IR1, (LPCTSTR *)lpszStrings, EVENTLOG_INFORMATION_TYPE); \
+ }
+
#ifdef PYSERVICE_BUILD_DLL // The bulk of this file is only used when building the core DLL.
***************
*** 54,58 ****
// Globals
- HINSTANCE g_hdll = 0;
// Will be set to one of SERVICE_WIN32_OWN_PROCESS etc flags.
DWORD g_serviceProcessFlags = 0;
--- 63,66 ----
***************
*** 926,929 ****
--- 934,939 ----
embedded in it, use it, otherwise insist one is passed on the
command line
+ (NOTE: Embedding a resource to specify the service name is
+ deprecated)
*/
TCHAR svcNameBuf[256];
***************
*** 941,945 ****
}
bServiceDebug = TRUE;
! _tprintf(_T("Debugging service %s\n"), svcName);
PythonService_Initialize(NULL, NULL);
PythonService_PrepareToHostSingle(NULL);
--- 951,955 ----
}
bServiceDebug = TRUE;
! _tprintf(_T("Debugging service %s - press Ctrl+C to stop.\n"), svcName);
PythonService_Initialize(NULL, NULL);
PythonService_PrepareToHostSingle(NULL);
***************
*** 1077,1080 ****
--- 1087,1092 ----
// If not error loading, and not an empty string
+ // (NOTE: Embedding a resource to specify the service name is
+ // deprecated)
if (LoadStringA(GetModuleHandle(NULL), RESOURCE_SERVICE_NAME, buf, cchBuf)>1)
// Get out of here now!
***************
*** 1320,1324 ****
// Get the message text, and just print it.
if (FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY,
! GetModuleHandle(NULL), code, 0, (LPTSTR)&buffer, 0, (va_list *)inserts)==0) {
_tprintf(_T("%s 0x%X - No message available\nMessage inserts were"), szType, code);
for (int i=0;i<numInserts;i++)
--- 1332,1336 ----
// Get the message text, and just print it.
if (FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY,
! g_hdll, code, 0, (LPTSTR)&buffer, 0, (va_list *)inserts)==0) {
_tprintf(_T("%s 0x%X - No message available\nMessage inserts were"), szType, code);
for (int i=0;i<numInserts;i++)
***************
*** 1368,1377 ****
--- 1380,1392 ----
#else // PYSERVICE_BUILD_DLL
// Our EXE entry point.
+
int main(int argc, char **argv)
{
PyObject *module, *f;
+ PyThreadState *threadState;
HMODULE hmod;
FARPROC proc;
Py_Initialize();
+ PyEval_InitThreads();
module = PyImport_ImportModule("servicemanager");
if (!module) goto failed;
***************
*** 1395,1398 ****
--- 1410,1418 ----
goto failed;
}
+ // A little thread-state dance, as our module will attempt to acquire it.
+ threadState = PyThreadState_Swap(NULL);
+ PyThreadState_Swap(threadState);
+ PyEval_ReleaseThread(threadState);
+
typedef int (* FNPythonService_main)(int argc, char **argv);
return ((FNPythonService_main)proc)(argc, argv);
|