source/bases/Win32Service.c
//-----------------------------------------------------------------------------
// Service_Stop()
//   Stop the service. Note that the controlling thread must be ended before
// the main thread is ended or the control GUI does not understand that the
// service has ended.
//-----------------------------------------------------------------------------
Service_Stop()
Stop the service. Note that the controlling thread must be ended before
the main thread is ended or the control GUI does not understand that the
service has ended.
Service_Stop () Stop the service . Note that the controlling thread must be ended before the main thread is ended or the control GUI does not understand that the service has ended .
static int Service_Stop(udt_ServiceInfo* info)
{
    PyThreadState *threadState;
    PyObject *result;
    if (Service_SetStatus(info, SERVICE_STOP_PENDING) < 0)
        return LogWin32Error(GetLastError(), "cannot set service as stopping");
    gControlEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (!gControlEvent)
        return LogWin32Error(GetLastError(), "cannot create control event");
    threadState = PyThreadState_New(gInterpreterState);
    if (!threadState)
        return LogPythonException("unable to create new thread state");
    PyEval_AcquireThread(threadState);
    result = PyObject_CallMethod(gInstance, "stop", NULL);
    if (!result)
        result = PyObject_CallMethod(gInstance, "Stop", NULL);
    if (!result)
        return LogPythonException("exception calling stop method");
    Py_DECREF(result);
    PyThreadState_Clear(threadState);
    PyEval_ReleaseThread(threadState);
    PyThreadState_Delete(threadState);
    if (Service_SetStatus(info, SERVICE_STOPPED) < 0)
        return LogWin32Error(GetLastError(), "cannot set service as stopped");
    if (!SetEvent(gControlEvent))
        return LogWin32Error(GetLastError(), "cannot set control event");
    return 0;
}
static int Service_Stop ( udt_ServiceInfo * info ) { PyThreadState * threadState ; PyObject * result ; if ( Service_SetStatus ( info , SERVICE_STOP_PENDING ) < 0 ) return LogWin32Error ( GetLastError ( ) , " " ) ; gControlEvent = CreateEvent ( NULL , TRUE , FALSE , NULL ) ; if ( ! gControlEvent ) return LogWin32Error ( GetLastError ( ) , " " ) ; threadState = PyThreadState_New ( gInterpreterState ) ; if ( ! threadState ) return LogPythonException ( " " ) ; PyEval_AcquireThread ( threadState ) ; result = PyObject_CallMethod ( gInstance , " " , NULL ) ; if ( ! result ) result = PyObject_CallMethod ( gInstance , " " , NULL ) ; if ( ! result ) return LogPythonException ( " " ) ; Py_DECREF ( result ) ; PyThreadState_Clear ( threadState ) ; PyEval_ReleaseThread ( threadState ) ; PyThreadState_Delete ( threadState ) ; if ( Service_SetStatus ( info , SERVICE_STOPPED ) < 0 ) return LogWin32Error ( GetLastError ( ) , " " ) ; if ( ! SetEvent ( gControlEvent ) ) return LogWin32Error ( GetLastError ( ) , " " ) ; return 0 ; }
Service_Stop()
Stop the service.
Service_Stop () Stop the service .
// indicate that the service is being stopped // create event for the main thread to wait on for the control thread // create a new Python thread and acquire the global interpreter lock // call the "stop" method // destroy the Python thread and release the global interpreter lock // indicate that the service has stopped // now set the control event