CTRL-Z not working on Dev branch
twelsh37 opened this issue · comments
When i run main.py in my PyCharm IDE I get the question in the console, the first 3 questions go fine but when I enter a CTRL + Z on my PC it does not submit to the program. see below and the Traceback where I had to stop program execution.
C:\Users\Owner\PycharmProjects\test1-delete-me\.venv\Scripts\python.exe C:\Users\Owner\PycharmProjects\CodingCrew\src\main.py
Welcome to Project Builder.
Let's start by getting some basic information about the project.
Please, enter the project name: test project
Please, enter the full path of the project location (default: '%USERPROFILE%\Projects'):
Your project will be located at: '%USERPROFILE%\Projects\test_project'.
Is that OK? ([Yes]/No/eXit):
Yes
Please provide a detailed description of the project.
You can add multiple lines. Press 'Ctrl-Z' to submit.
lots of python files
output documents in encrypted pdfs
hash all code
Traceback (most recent call last):
File "C:\Users\Owner\PycharmProjects\CodingCrew\src\main.py", line 16, in <module>
wkf.invoke({}, debug=is_debugging)
File "C:\Users\Owner\PycharmProjects\test1-delete-me\.venv\lib\site-packages\langgraph\pregel\__init__.py", line 1333, in invoke
for chunk in self.stream(
File "C:\Users\Owner\PycharmProjects\test1-delete-me\.venv\lib\site-packages\langgraph\pregel\__init__.py", line 869, in stream
done, inflight = concurrent.futures.wait(
File "C:\Users\Owner\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 307, in wait
waiter.event.wait(timeout)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python310\lib\threading.py", line 607, in wait
signaled = self._cond.wait(timeout)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python310\lib\threading.py", line 320, in wait
waiter.acquire()
KeyboardInterrupt
Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)
Thanks Tom.
The CTRL+D and CTRL+Z are a quick temporary solution for the multiline input my intention is to use CTRL+ENTER to submit for both Linux and Windows.
But I will look into it to see how to fix it on windows.
I have been using the Linux environment and so far, it seems to work there.
Let me take a look at that. I have both windows and linux (Ubuntu) desktops so can test on both.
I will try and get a fix today
I took another look at this.
On windows you need to press CTRL +Z and then ENTER and it will end the multiline input. I am guessing it works fine on Linux as is.
i did play around a bit with utils.py and specifically the read_text() function.
I came upon with the following which takes 'Shift+ENTER' as a terminator but I then had issues displaying text. probably just some silliness on my end.
i did need to import two additional libs
Keyboard
readchar
Here is the commented code I came up with. maybe you can salvage something from it.
def read_text() -> Iterable[str]:
"""
Allows the user to enter a multiline string ending by pressing Shift+Enter.
Returns:
list[str]: The multiline string entered by the user.
"""
print("Start typing your text. Press 'Shift+Enter' to finish.")
multiline = list[str]()
line = ''
while True:
# If shift+enter is pressed
if keyboard.is_pressed('shift+enter'):
break
else:
c = readchar.readchar()
# print character as soon as it's typed
print(c, end="", flush=True)
line += c
# Enter key
if c == '\n':
# Shift wasn't pressed, move to next line and continue typing on console
multiline.append(line.rstrip())
line = ''
# Add the last line if it does not end with '\n'
multiline.append(line.rstrip())
# Debug to see whats returned
print(f'DEBUG1: {multiline}')
return multiline
Can you create a Pull Request from your fork into the dev branch of the original?
I can do a code review for that.
Oh. I've just tried the code on Linux.
Here is what I've got:
Traceback (most recent call last):
File "/home/andre/projects/coding-crew/src/main.py", line 16, in <module>
wkf.invoke({}, debug=is_debugging)
File "/home/andre/.local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 1249, in invoke
for chunk in self.stream(
File "/home/andre/.local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 835, in stream
_panic_or_proceed(done, inflight, step)
File "/home/andre/.local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 1338, in _panic_or_proceed
raise exc
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andre/.local/lib/python3.11/site-packages/langgraph/pregel/retry.py", line 66, in run_with_retry
task.proc.invoke(task.input, task.config)
File "/home/andre/.local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 2499, in invoke
input = step.invoke(
^^^^^^^^^^^^
File "/home/andre/.local/lib/python3.11/site-packages/langgraph/utils.py", line 89, in invoke
ret = context.run(self.func, input, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andre/projects/coding-crew/src/nodes/start_project.py", line 63, in create
lines += read_text()
^^^^^^^^^^^
File "/home/andre/projects/coding-crew/src/utils.py", line 202, in read_text
key = keyboard.read_key()
^^^^^^^^^^^^^^^^^^^
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/site-packages/keyboard/__init__.py", line 935, in read_key
event = read_event(suppress)
^^^^^^^^^^^^^^^^^^^^
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/site-packages/keyboard/__init__.py", line 924, in read_event
hooked = hook(queue.put, suppress=suppress)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/site-packages/keyboard/__init__.py", line 461, in hook
append(callback)
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/site-packages/keyboard/_generic.py", line 67, in add_handler
self.start_if_necessary()
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/site-packages/keyboard/_generic.py", line 35, in start_if_necessary
self.init()
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/site-packages/keyboard/__init__.py", line 196, in init
_os_keyboard.init()
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/site-packages/keyboard/_nixkeyboard.py", line 113, in init
build_device()
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/site-packages/keyboard/_nixkeyboard.py", line 109, in build_device
ensure_root()
File "/home/andre/.conda/envs/coding-crew/lib/python3.11/site-packages/keyboard/_nixcommon.py", line 174, in ensure_root
raise ImportError('You must be root to use this library on linux.')
ImportError: You must be root to use this library on linux.
This error:
*ImportError: You must be root to use this library on linux.
is from the keyboard.
I've tried that before but I forgot.
Added a code that works with CTRL+ENTER with both Windows and Linux.
It is committed in dev and will be in main in the next release.