Skip to content

Commit

Permalink
Interactive Streaming Output Support (#39)
Browse files Browse the repository at this point in the history
* Interactive Streaming via changing the run command

* Addressed issue/comments as well as adding test for scenario

* minor space change

* Added few more unit tests - working on utilizing other unit test methods to test the PS Kernel

* PowerShell Kernel Baseline Notebook Test

* Move ipynb test file to tests folder
  • Loading branch information
VasuBhog authored Oct 5, 2020
1 parent 6abe2b3 commit 2f0aa0d
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 9 deletions.
8 changes: 4 additions & 4 deletions powershell_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def banner(self):
return self._banner

language_info = {'name': 'powershell',
'version': "0.1.3",
'codemirror_mode': 'shell',
'mimetype': 'text/x-sh',
'file_extension': '.ps1'}
Expand Down Expand Up @@ -61,10 +62,9 @@ def do_execute(self, code, silent, store_history=True,
if not self.proxy:
self.__createProxy()

output = self.proxy.run_command(code)

message = {'name': 'stdout', 'text': output}
self.send_response(self.iopub_socket, 'stream', message)
for output in self.proxy.run_command(code):
message = {'name': 'stdout', 'text': output}
self.send_response(self.iopub_socket, 'stream', message)

return {'status': 'ok', 'execution_count': self.execution_count,
'payload': [], 'user_expressions': {}}
Expand Down
19 changes: 14 additions & 5 deletions powershell_kernel/powershell_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def __init__(self, repl):
self.expected_output_prefix = ''
self.expected_output_len = 0

# Returns a generator that yields string messages as they are returned from powershell via stdout
# this is a hack to detect when we stop processing this input
self.run_command('function prompt() {"^"}')

for temp in self.run_command('function prompt() {"^"}'):
continue

def run_command(self, input):
self.runCmdLock.acquire()
try:
Expand All @@ -59,10 +61,16 @@ def run_command(self, input):
self.output_prefix_stripped = False

self._repl.write(input + '\n')

while not self.stop_flag:
sleep(0.05)
return self.output
# Allows for interactive streaming of output
if not self.stop_flag:
powershell_message = self.output
self.output = ''
if powershell_message != '':
yield powershell_message
yield self.output

finally:
self.runCmdLock.release()

Expand Down Expand Up @@ -92,8 +100,9 @@ def update_view_loop(self):

def write(self, packet):
# this is a hack to detect when we stop processing this input
if packet == '^':
if packet.endswith('^'):
self.stop_flag = True
self.output += packet[:-1]
return
self.output += packet

Expand Down
Loading

0 comments on commit 2f0aa0d

Please sign in to comment.