TensorRT 6: dynamic shapes in thread

I want to create context in every thread.
for every thread,I create cuda context by pycuda.driver.Device.make_context and use the same engine to create trt context:

self.context = self.engine.create_execution_context()
self.context.active_optimization_profile=0

it’s works fine for fixed shapes(the second line is not used).
but for dynamic shapes,
when I execute the code second time in the second thread,the first line of code causes a warning:

[TensorRT] WARNING: Could not set default profile 0 for execution context. Profile index must be set explicitly.

and the second line of the code causes a error:

.......
    self.context.active_optimization_profile=0
IndexError: Profile index 0 is out of bounds.

Environment:
Ubuntu 18.04
CUDA 10.1
TensorRT 6.0.1.5 ga

Hi,

Multiple execution contexts may exist for one ICudaEngine instance, allowing the same engine to be used for the execution of multiple batches simultaneously.

If the engine supports dynamic shapes, each execution context in concurrent use must use a separate optimization profile.

Please refer to below link for more details:
https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/c_api/classnvinfer1_1_1_i_execution_context.html#details

Thanks