How could I cancel/terminate a long running workflow?

My scenario is that i want to implement a python code running engine. The code is given by users, so i dont know how long it will take to run.
I had tried the official documentation in the interrupted section, but it doesn’t work.
I just want to know if there is any way that i can build up this kind of engine. dose child workflow work?
Thanks!

You would invoke user code in an activity, so you will have to define a StartToClose timeout for it. Would set it to the max time you allow user code to run (can be long-running). You should also probably consider auto-heartbeating from this activity, could use decorator see sample here, so you can retry fast in case the activity worker becomes unavailable.