betodealmeida opened a new pull request #13041:
URL: https://github.com/apache/superset/pull/13041


   ### SUMMARY
   <!--- Describe the change below, including rationale and design decisions -->
   
   We currently use a decorator to timeout queries that run in SQL Lab, eg:
   
   ```python
   with utils.timeout(seconds=timeout, error_message=timeout_msg):
       data = sql_lab.get_sql_results(...)
   ```
   
   The decorator uses `SIGALRM`, which is not available in Windows, resulting 
in an error (see https://github.com/apache/superset/issues/12824).
   
   Even though Windows is not technically supported, this is a simple fix. I 
introduced a new timeout decorator based on a timer.  This PR changes Superset 
to use that decorator only when running on Windows. In theory we could replace 
the old one, but I thought it would be safer to introduce the new one in 
parallel first.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   N/A
   
   ### TEST PLAN
   <!--- What steps should be taken to verify the changes -->
   
   I installed Python under a Windows VPS and tested the decorator with this 
script:
   
   ```python
   # test.py
   import _thread
   import threading
   
   
   class Timeout:
       def __init__(self, seconds: int = 1, error_message: str = "Timeout") -> 
None:
           self.seconds = seconds
           self.error_message = error_message
           self.timer = threading.Timer(self.seconds, _thread.interrupt_main)
   
       def __enter__(self) -> None:
           self.timer.start()
   
       def __exit__(self, type, value, traceback) -> None:
           if type is KeyboardInterrupt:
               raise Exception(self.error_message)
   
   
   with Timeout():
       for i in range(int(1e15)):
           pass
   ```
   
   (I didn't use `sleep()` because the `_thread.interrupt_main` doesn't 
interrupt it.)
   
   Then running it causes the main thread to be aborted after 1 second:
   
   ```
   C:\Users\Administrator\Documents>powershell -Command "Measure-Command 
{python test.py}"
   Traceback (most recent call last):
     File "C:\Users\Administrator\Documents\test.py", line 21, in <module>
       pass
   KeyboardInterrupt
   
   During handling of the above exception, another exception occurred:
   
   Traceback (most recent call last):
     File "C:\Users\Administrator\Documents\test.py", line 21, in <module>
       pass
     File "C:\Users\Administrator\Documents\test.py", line 16, in __exit__
       raise Exception(self.error_message)
   Exception: Timeout
   
   
   Days              : 0
   Hours             : 0
   Minutes           : 0
   Seconds           : 1
   Milliseconds      : 463
   Ticks             : 14631515
   TotalDays         : 1.69346238425926E-05
   TotalHours        : 0.000406430972222222
   TotalMinutes      : 0.0243858583333333
   TotalSeconds      : 1.4631515
   TotalMilliseconds : 1463.1515
   
   
   
   
   C:\Users\Administrator\Documents>
   ```
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [x] Has associated issue: https://github.com/apache/superset/issues/12824
   - [ ] Changes UI
   - [ ] Requires DB Migration.
   - [ ] Confirm DB Migration upgrade and downgrade tested.
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to