title: Python- How to communicate with printer
body: <p>I've been searching for a few days on how to improve a program I wrote for work. The program, which uses python 3.6, simply sends pre-formatted .doc files to the printer, but I can't seem to find a way on how to signal the function to stop sending the file to print once the printer has run out of paper. The number of documents printed varies, so I can't just use a simple range function.</p>
  
  <p>I've looked into the win32print module and the pycups module (which won't pip install not matter what I try). Is there something in the signal module that captures external error messages from other apps? Ideally, what would be great, is if the python script could check the status of the print queue first, before sending the file.</p>
  
  <p>I found that the code below, using the win32print module, that should accomplish this, but it doesn't seem to work.</p>
  
  <pre><code>import win32print
  
  p = win32print.OpenPrinter("Canon Inkjet iP1800 series")
  
  raw = win32print.EnumJobs(p, 0, 999)
  
  def main():
      while len(raw) &gt; 0:
          #does some function
  
      if #receives error from printer:
          break
  
  main()
  
  win32print.ClosePrinter(p)
  </code></pre>