Skip to content

Commit 2f5a7b3

Browse files
committed
Check: fix the input() not working in normal scripts
1 parent dbe419a commit 2f5a7b3

2 files changed

Lines changed: 115 additions & 2 deletions

File tree

deployment/get-staging-url.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
# Quick script to find the current staging environment URL
3+
# ECS tasks with public IPs get new IPs on every redeployment
4+
5+
set -e
6+
7+
echo "🔍 Finding staging environment URL..."
8+
echo ""
9+
10+
# Ensure AWS profile is set
11+
export AWS_PROFILE=personal
12+
REGION="us-east-2"
13+
CLUSTER="pythonide-cluster"
14+
SERVICE="pythonide-staging-service"
15+
16+
# Get the running task ARN
17+
echo "📋 Getting task ARN..."
18+
TASK_ARN=$(aws ecs list-tasks \
19+
--cluster "$CLUSTER" \
20+
--service-name "$SERVICE" \
21+
--region "$REGION" \
22+
--query 'taskArns[0]' \
23+
--output text)
24+
25+
if [ -z "$TASK_ARN" ] || [ "$TASK_ARN" = "None" ]; then
26+
echo "❌ No running tasks found for staging service"
27+
exit 1
28+
fi
29+
30+
TASK_ID=$(echo "$TASK_ARN" | awk -F'/' '{print $NF}')
31+
echo "✅ Task ID: $TASK_ID"
32+
echo ""
33+
34+
# Get network interface ID from task
35+
echo "🌐 Getting network interface..."
36+
ENI=$(aws ecs describe-tasks \
37+
--cluster "$CLUSTER" \
38+
--tasks "$TASK_ID" \
39+
--region "$REGION" \
40+
--query 'tasks[0].attachments[0].details[?name==`networkInterfaceId`].value' \
41+
--output text)
42+
43+
if [ -z "$ENI" ] || [ "$ENI" = "None" ]; then
44+
echo "❌ Could not find network interface for task"
45+
exit 1
46+
fi
47+
48+
echo "✅ Network Interface: $ENI"
49+
echo ""
50+
51+
# Get public IP from network interface
52+
echo "📍 Getting public IP..."
53+
PUBLIC_IP=$(aws ec2 describe-network-interfaces \
54+
--network-interface-ids "$ENI" \
55+
--region "$REGION" \
56+
--query 'NetworkInterfaces[0].Association.PublicIp' \
57+
--output text)
58+
59+
if [ -z "$PUBLIC_IP" ] || [ "$PUBLIC_IP" = "None" ]; then
60+
echo "❌ Task does not have a public IP"
61+
exit 1
62+
fi
63+
64+
echo "✅ Public IP: $PUBLIC_IP"
65+
echo ""
66+
echo "================================================"
67+
echo "🎯 STAGING URL:"
68+
echo " http://$PUBLIC_IP:8080"
69+
echo "================================================"
70+
echo ""
71+
echo "📝 Credentials:"
72+
echo " Admin: sa9082 / Admin@sa9082"
73+
echo " Student: test_1 / student@test_1"
74+
echo ""

server/command/hybrid_repl_thread.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,47 @@ def read_pty_output(self):
987987
print(f"[PTY-DEBUG] ✓ Timeout monitor will now exit (REPL mode active)")
988988
self.response_to_client(5000, {"mode": "repl"})
989989

990-
# For PTY mode with native input(), we don't need INPUT_REQUEST markers
991-
# The prompts appear naturally in the output stream
990+
# Check for matplotlib figures
991+
if "__MATPLOTLIB_FIGURE_START__" in buffer and "__MATPLOTLIB_FIGURE_END__" in buffer:
992+
start = buffer.index("__MATPLOTLIB_FIGURE_START__") + len("__MATPLOTLIB_FIGURE_START__")
993+
end = buffer.index("__MATPLOTLIB_FIGURE_END__")
994+
figure_data = buffer[start:end].strip()
995+
996+
# Send figure to client
997+
self.response_to_client(3000, {"figure": figure_data})
998+
999+
# Clear the marker from buffer
1000+
buffer = buffer[end + len("__MATPLOTLIB_FIGURE_END__"):]
1001+
1002+
# CRITICAL: Check for INPUT_REQUEST markers from custom input() during script execution
1003+
if "__INPUT_REQUEST_START__" in buffer and "__INPUT_REQUEST_END__" in buffer:
1004+
# Extract the positions
1005+
marker_start = buffer.index("__INPUT_REQUEST_START__")
1006+
marker_end = buffer.index("__INPUT_REQUEST_END__") + len("__INPUT_REQUEST_END__")
1007+
1008+
# Extract prompt from markers
1009+
prompt_start = marker_start + len("__INPUT_REQUEST_START__")
1010+
prompt_end = buffer.index("__INPUT_REQUEST_END__")
1011+
prompt = buffer[prompt_start:prompt_end]
1012+
1013+
# Send any text before the marker
1014+
pre_marker = buffer[:marker_start]
1015+
if pre_marker and pre_marker.strip():
1016+
for line in pre_marker.split("\n"):
1017+
if line or line == "":
1018+
self.response_to_client(0, {"stdout": line})
1019+
1020+
print(f"[PTY-DEBUG] Input request detected: {repr(prompt)}")
1021+
1022+
# Pause timeout when waiting for user input
1023+
self.waiting_for_input = True
1024+
1025+
# Send input request signal to enable input field (with prompt for frontend)
1026+
# The frontend will display the prompt, so we don't need to send it separately
1027+
self.response_to_client(2000, {"prompt": prompt})
1028+
1029+
# Clear the processed part from buffer
1030+
buffer = buffer[marker_end:].lstrip('\n')
9921031

9931032
# Send complete lines to client
9941033
while '\n' in buffer or '\r' in buffer:

0 commit comments

Comments
 (0)