Add logging to debug threading local issue

Finally change _local_context to set as local in the module level