anirudh2290 commented on a change in pull request #10833: [WIP] Change class 
variables to thread local variables
URL: https://github.com/apache/incubator-mxnet/pull/10833#discussion_r187244425
 
 

 ##########
 File path: python/mxnet/context.py
 ##########
 @@ -109,15 +112,37 @@ def __repr__(self):
         return self.__str__()
 
     def __enter__(self):
-        self._old_ctx = Context.default_ctx
-        Context.default_ctx = self
+        if not hasattr(Context._default_ctx, "value"):
 
 Review comment:
   what about a situation like below:
   ```
   import threading
   import mxnet as mx
   
   def test_context():
       ctx_list = []
       def f():
           mx.context.Context.default_ctx
           ctx_list.append(Context.default_ctx)
       thread = threading.Thread(target=f)
       thread.start()
       thread.join()
   
   if __name__ == '__main__':
       test_context()
   ```
   
   Without hasattr this doesn't work.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to