title: mp.set_start_method('spawn') triggered an error saying the context is already been set
body: <p>Here is my full <a href="https://colab.research.google.com/drive/11S0q3QcBWzHX4Rxluu2Zu8svd4h4fI_-#scrollTo=tGmZePPYsEM9" rel="noreferrer">code</a></p>
  
  <p>I have succeeded to reproduce the behavior of my main code with a little snippet. </p>
  
  <p>In a <strong>Google Colab Env</strong>, suppose I setup <code>hardware accelerator</code> to <code>GPU</code>. </p>
  
  <p>Here is the little <a href="https://colab.research.google.com/drive/19mL5jh1CsOaz-SouoelJRc4TkE4KvZUP?usp=sharing" rel="noreferrer">snippet</a> :</p>
  
  <pre><code>import multiprocessing as mp
  
  def foo(q):
      q.put('hello')
  
  if __name__ == '__main__':
      mp.set_start_method('spawn')
      q = mp.Queue()
      p = mp.Process(target=foo, args=(q,))
      p.start()
      print(q.get())
      p.join()
  </code></pre>
  
  <p>With <code>mp.set_start_method('spawn')</code>, I got the error <code>RuntimeError: context has already been set</code> and if I use <code>mp.set_start_method('spawn', force=True)</code> it got stuck in an infinite loop if I can say.</p>
  
  <p>Is there any way I can prevent that error from occurring in the Colab Env?</p>
  
  <p><strong>P.S.</strong> Be aware <code>mp.set_start_method('spawn')</code> this line of code is necessary in my code. Otherwise, I got the error <code>RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method</code></p>
  
  <p><strong>Overkilled Solution</strong></p>
  
  <p><a href="https://i.stack.imgur.com/p2NmD.png" rel="noreferrer"><img src="https://i.stack.imgur.com/p2NmD.png" alt="enter image description here"></a></p>
  
  <p>The problem here is that the spawned subprocess can't find <code>__main__.foo</code>.</p>
  
  <p>One (less than perfect) option is to put the code in a separate file, e.g. make a new directory and add it to the path.</p>
  
  <p>I don't want to use that solution because it is way overkilled for my main code. Maybe it will guide you to a more elegant solution.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This seems to be a more reasonable solution, but still looking for an answer more elegant.</p>
  
  <p><a href="https://i.stack.imgur.com/wNNVu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wNNVu.png" alt="enter image description here"></a></p>