title: "UnboundLocalError: local variable 'status' referenced before assignment" and "status_1" is not accessed by Pylance
body: <p>This script should tell me if another python file is running or not running and prints file on/file off every time the file stops/starts running:</p>
  <pre class="lang-py prettyprint-override"><code>import psutil
  import os
  status = True
  status_1 = True
  while True:
      def is_running(script):
          for q in psutil.process_iter():
              if q.name().startswith('python'):
                  if len(q.cmdline())&gt;1 and script in q.cmdline()[1] and q.pid !=os.getpid():
                      if status:
                          status_1 = True #&quot;status_1&quot; is not accessed by Pylance
                          status = False
                          print('file on')
      if not is_running(&quot;test.py&quot;):
          if status_1:
              status = True
              status_1 = False
              print('file off')
  </code></pre>
  <p>The error:</p>
  <pre class="lang-py prettyprint-override"><code>Traceback (most recent call last):
    File &quot;c:\Users\Win10\file.py&quot;, line 27, in &lt;module&gt;
      if not is_running(&quot;test.py&quot;):
    File &quot;c:\Users\Win10\file.py&quot;, line 23, in is_running
      if status:
  UnboundLocalError: local variable 'status' referenced before assignment
  </code></pre>
  <p>I am using vs code by the way.</p>