Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

periodically do work or exit in python coroutine/task

$
0
0

Completely new to python. I wanna write a simple async function that does a ps $pid every N seconds until it receives a stop signal.i.e in go it'd simply be:

go func(cancelCtx context.Context) { ticker, cancel := time.NewTicker(time.Second) defer cancel() looper:   for {     select {       case <-ticker.C:         checkProcess()       case <-ctx.Done():         break looper      }    } fmt.Println("exited")}(ctx)

I'm slowly ramping up on python asyncio but hoping to at least get some general guidance on the best pythonic approach. Thanks.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>