From 3b7e9f99b61538e0bbd6f07deeb7f7cb12013ed5 Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Fri, 9 Dec 2016 15:18:08 -0800 Subject: ICE-7138 - new Python AMI mapping based on futures and modified AMD mapping --- python/modules/IcePy/Communicator.cpp | 59 +++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'python/modules/IcePy/Communicator.cpp') diff --git a/python/modules/IcePy/Communicator.cpp b/python/modules/IcePy/Communicator.cpp index eb223c85853..927c3cab5d2 100644 --- a/python/modules/IcePy/Communicator.cpp +++ b/python/modules/IcePy/Communicator.cpp @@ -719,6 +719,48 @@ communicatorFlushBatchRequests(CommunicatorObject* self) return Py_None; } +#ifdef WIN32 +extern "C" +#endif +static PyObject* +communicatorFlushBatchRequestsAsync(CommunicatorObject* self, PyObject* /*args*/, PyObject* /*kwds*/) +{ + assert(self->communicator); + const string op = "flushBatchRequests"; + + FlushAsyncCallbackPtr d = new FlushAsyncCallback(op); + Ice::Callback_Communicator_flushBatchRequestsPtr cb = + Ice::newCallback_Communicator_flushBatchRequests(d, &FlushAsyncCallback::exception, &FlushAsyncCallback::sent); + + Ice::AsyncResultPtr result; + + try + { + AllowThreads allowThreads; // Release Python's global interpreter lock during remote invocations. + + result = (*self->communicator)->begin_flushBatchRequests(cb); + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return 0; + } + + PyObjectHandle asyncResultObj = createAsyncResult(result, 0, 0, self->wrapper); + if(!asyncResultObj.get()) + { + return 0; + } + + PyObjectHandle future = createFuture(op, asyncResultObj.get()); + if(!future.get()) + { + return 0; + } + d->setFuture(future.get()); + return future.release(); +} + #ifdef WIN32 extern "C" #endif @@ -1608,6 +1650,8 @@ static PyMethodDef CommunicatorMethods[] = PyDoc_STR(STRCAST("setDefaultLocator(proxy) -> None")) }, { STRCAST("flushBatchRequests"), reinterpret_cast(communicatorFlushBatchRequests), METH_NOARGS, PyDoc_STR(STRCAST("flushBatchRequests() -> None")) }, + { STRCAST("flushBatchRequestsAsync"), reinterpret_cast(communicatorFlushBatchRequestsAsync), + METH_NOARGS, PyDoc_STR(STRCAST("flushBatchRequestsAsync() -> Ice.Future")) }, { STRCAST("begin_flushBatchRequests"), reinterpret_cast(communicatorBeginFlushBatchRequests), METH_VARARGS | METH_KEYWORDS, PyDoc_STR(STRCAST("begin_flushBatchRequests([_ex][, _sent]) -> Ice.AsyncResult")) }, @@ -1734,8 +1778,19 @@ IcePy::getCommunicatorWrapper(const Ice::CommunicatorPtr& communicator) CommunicatorMap::iterator p = _communicatorMap.find(communicator); assert(p != _communicatorMap.end()); CommunicatorObject* obj = reinterpret_cast(p->second); - Py_INCREF(obj->wrapper); - return obj->wrapper; + if(obj->wrapper) + { + Py_INCREF(obj->wrapper); + return obj->wrapper; + } + else + { + // + // Communicator must have been destroyed already. + // + Py_INCREF(Py_None); + return Py_None; + } } extern "C" -- cgit v1.2.3