Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 540dc3e

Browse files
committed
Fix perf issue where main event loop takes 100% of CPU
We have a 2 threads: Thread #1 runs in a loop polling the response queue Thread #2 runs in a loop decoding responses from the sqltoolsservice over stdout and posting them to the response queue Since thread #1 doesn't sleep, it's takes 100% CPU. In addition, running python 2.7 on windows, #2 doesn’t preempt the CPU due to #1 taking all of the CPU cycles, so no response is processed. Fix is simple – thread #1 needs to sleep so thread #2 can get scheduled and get it’s work done.
1 parent ca49239 commit 540dc3e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mssqlscripter/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ def main(args):
8686
scripting_request.execute()
8787

8888
while not scripting_request.completed():
89+
# The sleep prevents burning up the CPU and lets other threads get scheduled.
90+
time.sleep(0.1)
8991
response = scripting_request.get_response()
90-
9192
if response:
9293
scriptercallbacks.handle_response(response, parameters.DisplayProgress)
9394

0 commit comments

Comments
 (0)