|
12 | 12 |
|
13 | 13 | settings = sublime.load_settings("Languages.sublime-settings") |
14 | 14 |
|
| 15 | +DEFAULT_TIMEOUT = 3 |
| 16 | + |
15 | 17 |
|
16 | 18 | class Environment(object): |
17 | 19 | """ Environment for target file. |
@@ -113,12 +115,26 @@ def execute(input_view, output_view): |
113 | 115 | stderr=subprocess.STDOUT, |
114 | 116 | universal_newlines=True |
115 | 117 | ) |
116 | | - output, errors = run.communicate(Environment.last_input_view.substr(sublime.Region(0, input_view.size()))) |
117 | | - run.wait(); |
118 | | - output_view.run_command("output_file_edit", {"append": run.args + "\n\n"}); |
119 | | - output_view.run_command("output_file_edit", {"append": "------------------------------------------\n"}); |
120 | | - output_view.run_command("output_file_edit", {"append": output + "\n"}); |
121 | | - output_view.run_command("output_file_edit", {"append": "------------------------------------------\n"}); |
| 118 | + output_view.run_command("output_file_edit", {"append": run.args + "\n\n"}); |
| 119 | + output = None |
| 120 | + timeout = DEFAULT_TIMEOUT |
| 121 | + if "timeout" in lang_settings: |
| 122 | + timeout = lang_settings["timeout"] |
| 123 | + |
| 124 | + try: |
| 125 | + output, errors = run.communicate(Environment.last_input_view.substr(sublime.Region(0, input_view.size())), timeout=timeout) |
| 126 | + except subprocess.TimeoutExpired: |
| 127 | + output_view.run_command("output_file_edit", {"append": "Timeout expired of " + str(timeout) + " seconds\n"}); |
| 128 | + output_view.run_command("output_file_edit", {"append": "Timeout is added to stop running the process indefinitely, It can be changed in Languages.sublime-settings\n"}); |
| 129 | + run.kill() |
| 130 | + output, errors = run.communicate() |
| 131 | + finally: |
| 132 | + if output != None: |
| 133 | + output_view.run_command("output_file_edit", {"append": "------------------------------------------\n"}); |
| 134 | + output_view.run_command("output_file_edit", {"append": output + "\n"}); |
| 135 | + output_view.run_command("output_file_edit", {"append": "------------------------------------------\n"}); |
| 136 | + |
| 137 | + |
122 | 138 | output_view.run_command("output_file_edit", |
123 | 139 | {"append": "Execution finished with exit code : " + str(run.returncode)}) |
124 | 140 |
|
|
0 commit comments