Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit 5bba3f9

Browse files
committed
improved process, stdout, stderr handling
1 parent a5e9349 commit 5bba3f9

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

.bumpversion.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.9.0
2+
current_version = 0.9.1
33
files = SQLTools.py
44
tag = True
55
commit = True

SQLTools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "v0.9.0"
1+
__version__ = "v0.9.1"
22

33
import sys
44
import os

SQLToolsAPI/Command.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ def run(self):
3737
si = subprocess.STARTUPINFO()
3838
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
3939

40+
# select appropriate file handle for stderr
41+
# usually we want to redirect stderr to stdout, so erros are shown
42+
# in the output in the right place (where they actually occurred)
43+
# only if silenceErrors=True, we separate stderr from stdout and discard it
44+
stderrHandle = subprocess.STDOUT
45+
if self.silenceErrors:
46+
stderrHandle = subprocess.PIPE
47+
4048
self.process = subprocess.Popen(self.args,
4149
stdout=subprocess.PIPE,
42-
stderr=subprocess.PIPE,
50+
stderr=stderrHandle,
4351
stdin=subprocess.PIPE,
4452
env=os.environ.copy(),
4553
startupinfo=si)
@@ -52,6 +60,9 @@ def run(self):
5260
'replace').replace('\r', ''))
5361

5462
queryTimerEnd = time.time()
63+
# we are done with the output, terminate the process
64+
self.process.terminate()
65+
5566
if 'show_query' in self.options and self.options['show_query']:
5667
resultInfo = "/*\n-- Executed querie(s) at {0} took {1:.3f}ms --".format(
5768
str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(queryTimerStart))),
@@ -61,6 +72,10 @@ def run(self):
6172
resultInfo, resultLine, self.query, resultLine)
6273
return self.callback(resultString)
6374

75+
return
76+
77+
# regular mode is handled with more reliable Popen.communicate
78+
# which also terminates the process afterwards
6479
results, errors = self.process.communicate(input=self.query.encode())
6580

6681
queryTimerEnd = time.time()
@@ -110,6 +125,10 @@ def stop(self):
110125
if not self.process:
111126
return
112127

128+
# if poll returns None - proc still running, otherwise returns process return code
129+
if self.process.poll() is not None:
130+
return
131+
113132
try:
114133
# Windows does not provide SIGKILL, go with SIGTERM
115134
sig = getattr(signal, 'SIGKILL', signal.SIGTERM)

messages.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"0.3.0": "messages/v0.3.0.md",
66
"0.3.1": "messages/v0.3.0.md",
77
"0.8.2": "messages/v0.8.2.md",
8-
"0.9.0": "messages/v0.9.0.md"
8+
"0.9.0": "messages/v0.9.0.md",
9+
"0.9.1": "messages/v0.9.1.md"
910
}

messages/v0.9.1.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## v0.9.1 Notes
2+
3+
### Improvements
4+
5+
* Display errors inline instead of appending them at the bottom [#92](https://github.com/mtxr/SQLTools/issues/92)
6+
7+
8+
### Fixes
9+
10+
* Thread timeout is always triggered when streaming results output (MacOS) [#90](https://github.com/mtxr/SQLTools/issues/90)
11+
* stderr output is ignored when streaming results output [#91](https://github.com/mtxr/SQLTools/issues/91)

0 commit comments

Comments
 (0)