I thought this would just be a quick and easy problem to solve, but alas it is not.
I’m trying to find a way of sending a “CancellationToken” from my python client implementation which communicates with my C# Server.
With the C# client implementation I can simply implement:
var tokenSource = new CancellationTokenSource();
while (await priceResponse.ResponseStream.MoveNext(tokenSource.Token))
The Server code:
public async override Task Prices(PricesRequest request, IServerStreamWriter<PricesResponse> responseStream, ServerCallContext context)
{
...
while (!context.CancellationToken.IsCancellationRequested)
{
...
Does anyone know how to implement the cancellation pattern using python to communicate with the C# Server, or am I going about this the wrong way?
Thanks for any advice or opinions 🙂
I tried this – but to no avail…
class CancellationToken:
def __init__(self):
self._is_canceled = False
def is_canceled(self):
return self._is_canceled
def cancel(self):
self._is_canceled = True
But I’m relatively poor at python – so took this from some other more enlightened soul 🙂
PureAlpha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.