title: PyCUDA context error when using Flask
body: <p>I am using the PyCUDA to implement the smooth_local_affine as shown <a href="https://github.com/LouieYang/deep-photo-styletransfer-tf/blob/master/smooth_local_affine.py" rel="noreferrer">here</a>. It works well when I simply run the program on linux. But when I tried to import it under Flask context:</p>
  
  <pre><code>from smooth_local_affine import smooth_local_affine
  from flask import Flask
  app = Flask(_name_)
  ...
  </code></pre>
  
  <p>The following error occurs:</p>
  
  <blockquote>
  <pre><code>-------------------------------------------------------------------  
  PyCUDA ERROR: The context stack was not empty upon module cleanup.
  -------------------------------------------------------------------   
  A context was still active when the context stack was being cleaned up.  
  At this point in our execution, CUDA may already have been deinitialized, 
  so there is no way we can finish cleanly. The program will be aborted now. 
  Use Context.pop() to avoid this problem.
  </code></pre>
  </blockquote>
  
  <p>Then I tried to add <code>context.pop()</code>,then another error occurs;</p>
  
  <blockquote>
    <p>Error in atexit._run_exitfuncs: Traceback (most recent call last):<br>
    File
    "/home/yifang/anaconda3/envs/python3/lib/python3.6/site-packages/pycuda-2017.1-py3.6-linux-x86_64.egg/pycuda/autoinit.py",
    line 14, in _finish_up
        context.pop() pycuda._driver.LogicError: context::pop failed: invalid device context - cannot pop non-current context</p>
  </blockquote>
  
  <p>Anyone knows how to run PyCuda in Flask environment? Or maybe any alternative ways that I can use this smooth_local_affine feature without using PyCuda?</p>