Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose engine shutdown to adapter manager and push/pushpull adapters #312

Merged
merged 13 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions cpp/csp/python/PyAdapterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ static PyObject * PyAdapterManager_PyObject_shutdown_engine( PyAdapterManager_Py
if( !PyArg_ParseTuple( args, "O", &pyException ) )
argaj marked this conversation as resolved.
Show resolved Hide resolved
return NULL;

if( !PyExceptionInstance_Check( pyException ) )
{
std::string desc = "Expected Exception object as argument for shutdown_engine: got " + std::string( Py_TYPE( pyException ) -> tp_name );
self -> manager -> rootEngine() -> shutdown( std::make_exception_ptr( csp::Exception( "TypeError", desc ) ) );
}
else
self -> manager -> rootEngine() -> shutdown( std::make_exception_ptr( PythonPassthrough( pyException ) ) );
self -> manager -> rootEngine() -> shutdown( PyEngine_shutdownMakeException( pyException ) );

CSP_RETURN_NONE;
}
Expand Down
22 changes: 15 additions & 7 deletions cpp/csp/python/PyEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ class CSPIMPL_EXPORT PyEngine final: public PyObject
Engine * m_engine;
};

inline std::exception_ptr PyEngine_shutdownMakeException( PyObject * pyException )
argaj marked this conversation as resolved.
Show resolved Hide resolved
{
if( !PyExceptionInstance_Check( pyException ) )
{
PyObject* pyExceptionStr = PyObject_Str( pyException );
argaj marked this conversation as resolved.
Show resolved Hide resolved
std::string pyExceptionString = PyUnicode_AsUTF8( pyExceptionStr );
std::string desc = "Expected Exception object as argument for shutdown_engine: got " + pyExceptionString + "of type " + Py_TYPE( pyException ) -> tp_name;
argaj marked this conversation as resolved.
Show resolved Hide resolved
Py_DECREF(pyExceptionStr);
argaj marked this conversation as resolved.
Show resolved Hide resolved
return std::make_exception_ptr( csp::Exception( "TypeError", desc ) );
}
else
return std::make_exception_ptr( PythonPassthrough( pyException ) );
}

// Generic engine shutdown function for push-type adapters
template<typename T>
PyObject * PyEngine_shutdown( T * self, PyObject * args, PyObject * kwargs )
argaj marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -65,13 +79,7 @@ PyObject * PyEngine_shutdown( T * self, PyObject * args, PyObject * kwargs )
if( !PyArg_ParseTuple( args, "O", &pyException ) )
return NULL;

if( !PyExceptionInstance_Check( pyException ) )
{
std::string desc = "Expected Exception object as argument for shutdown_engine: got " + std::string( Py_TYPE( pyException ) -> tp_name );
self -> adapter -> rootEngine() -> shutdown( std::make_exception_ptr( csp::Exception( "TypeError", desc ) ) );
}
else
self -> adapter -> rootEngine() -> shutdown( std::make_exception_ptr( PythonPassthrough( pyException ) ) );
self -> adapter -> rootEngine() -> shutdown( PyEngine_shutdownMakeException( pyException ) );

CSP_RETURN_NONE;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/how-tos/Write-Realtime-Input-Adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,6 @@ def _run(self):
while self._running:
try:
requests.get(endpoint) # API call over a network, may fail
catch Exception as exc:
except Exception as exc:
self.shutdown_engine(exc)
```