title: Running pypupeteer in FLASK gives ValueError: signal only works in main thread
body: <p>I am trying to integrate pyppeteer in a flask app. I have python script that runs pyppeteer and takes a screenshot of a page.This is working file if I run the script individually.</p>
  
  <p>The <strong>PROBLEM</strong> is the same script does not work when i run it in a FLASK APP.</p>
  
  <p>I get the following error :</p>
  
  <pre><code>loop.run_until_complete(capture(url, 123123))
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/
  Versions/3.7/lib/python3.7/asyncio/base_events.py", 
  line 568, in run_until_complete
  return future.result()
  File "/App-path/flaskr/image_capture/__init__.py", line 6, in capture
  browser = await launch()
  File "/usr/local/lib/python3.7/site-packages/pyppeteer/launcher.py", 
  line 311, in launch
  return await Launcher(options, **kwargs).launch()
  File "/usr/local/lib/python3.7/site-packages/pyppeteer/launcher.py", 
  line 180, in launch
  signal.signal(signal.SIGINT, _close_process)
  File"/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/
  Versions/3.7/lib/python3.7/signal.py", line 47, in signal
  handler = _signal.signal(_enum_to_int(signalnum), 
  _enum_to_int(handler))
  ValueError: signal only works in main thread.
  </code></pre>
  
  <p>The following code is used to capture screenshot.</p>
  
  <pre><code>async def capture(code_url, codeId):
  browser = await launch()
  # print('Hello')
  page = await browser.newPage()
  await page.setContent('&lt;div id="chart-container"&gt;ABCD&lt;/div&gt;')
  # print(await page.content())
  await page.addScriptTag({'url':'''{code_url}'''})
  await page.waitFor('.animateon')
  await page.setViewport({
      'width':await 
  page.evaluate('''document.documentElement.clientWidth''') ,
      'height': await 
  page.evaluate('''document.documentElement.clientHeight'''),
      'deviceScaleFactor': 10,
  })
  await page.screenshot({'path': '''./temp/screenshot/chart- 
  {codeId}.jpg''', 'type': 'jpeg'})
  await browser.close()
  </code></pre>
  
  <p>The following code is where this method is called :</p>
  
  <pre><code>@app.route('/api/v1/screenshot', methods=["POST"])
  def screenShot():
      url = request.form['url']
      loop.run_until_complete(capture(url, 123123))
      return jsonify("Image captured Successfully!")
  </code></pre>
  
  <p>I am using asyncio loop to handle the async capture function.</p>
  
  <p>Also as per some suggestion from Stackoverflow questions I have turned off the debugging mode.</p>
  
  <p>Please suggest where I am going wrong.</p>
  
  <p>Python Version : 3.7</p>