Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4b94d6f

Browse files
authored
Merge pull requestalexmojaki#299 from alexmojaki/new-sync-message
New sync message
2 parents51eea8e +e2888d6 commit4b94d6f

File tree

10 files changed

+90
-43
lines changed

10 files changed

+90
-43
lines changed

‎build.sh‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ set -eux
55
rm -rf dist||true
66
mkdir -p dist/course/
77

8-
source$HOME/.poetry/env
9-
108
poetry run python -m translations.generate_po_file
119
poetry run python -m core.generate_static_files
1210

‎ci_test.sh‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ set -eux
55
export DISPLAY=:99
66
chromedriver --url-base=/wd/hub&
77
npm install -g firebase-tools
8-
source$HOME/.poetry/env
98
firebase emulators:exec"poetry run pytest tests"

‎core/checker.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ def reset(self):
4343

4444
self.console.locals.update(assert_equal=assert_equal)
4545

46-
defnon_str_input(self):
47-
raiseKeyboardInterrupt
48-
4946

5047
runner=FullRunner()
5148

‎core/generate_static_files.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ def get_roots():
6262

6363
relative=strip_required_prefix(f,site_packages)
6464
root=relative.split(os.path.sep)[0]
65+
66+
ifroot=="_distutils_hack":
67+
continue
68+
6569
roots.add(root)
6670

6771
mod_names.append(module.__name__)

‎core/runner/runner.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,28 @@ def serialize_syntax_error(self, exc, source_code):
4141
return {
4242
"text":friendly_syntax_error(exc,self.filename),
4343
}
44+
45+
defnon_str_input(self):
46+
# TODO do this in python_runner, then return early
47+
line=self.line
48+
self.line=""
49+
50+
ifline==1:
51+
raiseKeyboardInterrupt
52+
elifline==2:
53+
raiseRuntimeError(
54+
"The service worker for reading input isn't working. "
55+
"Try closing all futurecoder tabs, then reopening."
56+
)
57+
elifline==3:
58+
raiseRuntimeError(
59+
"This browser doesn't support reading input. "
60+
"Try upgrading to the most recent version or switching to a different browser, e.g. Chrome/Firefox. "
61+
"The browser must support SharedArrayBuffer or Service Workers."
62+
)
63+
else:
64+
# TODO raise specific exception to trigger proper feedback
65+
raiseRuntimeError(
66+
"Oops, something went wrong while reading input! "
67+
"Please report this error!"
68+
)

‎frontend/package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎frontend/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"redux-logger":"^3.0.6",
3737
"redux-thunk":"^2.3.0",
3838
"sass":"^1.32.8",
39-
"sync-message":"0.0.3"
39+
"sync-message":"0.0.8"
4040
},
4141
"scripts": {
4242
"start":"craco start",

‎frontend/src/RunCode.js‎

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import localforage from "localforage";
1818
import{animateScroll}from"react-scroll";
1919
importReactfrom"react";
2020
import*asSentryfrom"@sentry/react";
21-
import{makeAtomicsChannel,makeServiceWorkerChannel}from"sync-message";
21+
import{makeChannel,writeMessage}from"sync-message";
2222

2323
letworker,workerWrapper;
2424

@@ -29,19 +29,10 @@ function initWorker() {
2929

3030
initWorker();
3131

32-
constchannelPromise=(async()=>{
33-
if(typeofSharedArrayBuffer!=="undefined"){
34-
returnmakeAtomicsChannel();
35-
}else{
36-
awaitnavigator.serviceWorker.register("./service-worker.js");
37-
constresult=awaitmakeServiceWorkerChannel({timeout:1000});
38-
if(!result){
39-
// TODO what if this doesn't work?
40-
window.location.reload();
41-
}
42-
returnresult;
43-
}
44-
})();
32+
constchannel=makeChannel({serviceWorker:{scope:"/course/"}});
33+
if(channel?.type==="serviceWorker"){
34+
navigator.serviceWorker.register("./service-worker.js");
35+
}
4536

4637
letinterruptBuffer=null;
4738
if(typeofSharedArrayBuffer!="undefined"){
@@ -51,14 +42,19 @@ if (typeof SharedArrayBuffer != "undefined") {
5142
exportconstterminalRef=React.createRef();
5243

5344
letawaitingInput=false;
45+
letsleeping=false;
5446
letpendingOutput=[];
5547

5648
localforage.config({name:"birdseye",storeName:"birdseye"});
5749

58-
functioninputCallback(messageId){
59-
awaitingInput=messageId;
60-
bookSetState("processing",false);
61-
terminalRef.current.focusTerminal();
50+
functioninputCallback(messageId,data){
51+
if(data.sleeping){
52+
sleeping=messageId;
53+
}else{
54+
awaitingInput=messageId;
55+
bookSetState("processing",false);
56+
terminalRef.current.focusTerminal();
57+
}
6258
}
6359

6460
exportletinterrupt=()=>{
@@ -73,7 +69,11 @@ export const runCode = async ({code, source}) => {
7369
if(awaitingInput){
7470
constmessageId=awaitingInput;
7571
awaitingInput=false;
76-
(awaitchannelPromise).writeInput({text:code},messageId);
72+
try{
73+
awaitwriteMessage(channel,{text:code},messageId);
74+
}catch{
75+
return;
76+
}
7777
bookSetState("processing",true);
7878
return;
7979
}
@@ -88,6 +88,7 @@ export const runCode = async ({code, source}) => {
8888
}
8989

9090
awaitingInput=false;
91+
sleeping=false;
9192
pendingOutput=[];
9293

9394
bookSetState("processing",true);
@@ -113,10 +114,11 @@ export const runCode = async ({code, source}) => {
113114
letinterruptResolver;
114115
constinterruptPromise=newPromise(r=>interruptResolver=r);
115116
interrupt=async()=>{
116-
if(awaitingInput){
117-
constmessageId=awaitingInput;
117+
if(awaitingInput||sleeping){
118+
constmessageId=awaitingInput||sleeping;
118119
awaitingInput=false;
119-
(awaitchannelPromise).writeInput({interrupted:true},messageId);
120+
sleeping=false;
121+
awaitwriteMessage(channel,{interrupted:true},messageId);
120122
}else{
121123
doInterrupt();
122124
}
@@ -162,14 +164,15 @@ export const runCode = async ({code, source}) => {
162164
interruptPromise,
163165
workerWrapper.runCode(
164166
entry,
165-
(awaitchannelPromise).channel,
167+
channel,
166168
interruptBuffer,
167169
Comlink.proxy(outputCallback),
168170
Comlink.proxy(inputCallback),
169171
),
170172
]);
171173

172174
awaitingInput=false;
175+
sleeping=false;
173176

174177
const{error}=data;
175178

‎frontend/src/Worker.js‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import*asComlinkfrom'comlink';
66
importpythonCoreUrlfrom"./python_core.tar.load_by_url"
77
importloadPythonStringfrom"!!raw-loader!./load.py"
8-
import{readChannel,syncSleep,uuidv4}from"sync-message";
8+
import{readMessage,ServiceWorkerError,syncSleep,uuidv4}from"sync-message";
99

1010
asyncfunctiongetPackageBuffer(){
1111
constresponse=awaitfetch(pythonCoreUrl);
@@ -67,13 +67,25 @@ async function runCode(entry, channel, interruptBuffer, outputCallback, inputCal
6767
awaitpyodideReadyPromise;
6868

6969
constfullInputCallback=(data)=>{
70-
constmessageId=uuidv4();
71-
inputCallback(messageId,toObject(data));
72-
constresult=readChannel(channel,messageId).text;
73-
if(result==null){
74-
returnnull;
70+
try{
71+
if(!channel){
72+
return3;// browser not supported
73+
}
74+
constmessageId=uuidv4();
75+
inputCallback(messageId,toObject(data));
76+
constresult=readMessage(channel,messageId).text;
77+
if(result==null){
78+
return1;// interrupt
79+
}
80+
returnresult+"\n";
81+
}catch(e){
82+
if(einstanceofServiceWorkerError){
83+
return2;// suggesting closing all tabs and reopening
84+
}else{
85+
console.error(e);
86+
return4;// general error
87+
}
7588
}
76-
returnresult+"\n";
7789
}
7890

7991
if(interruptBuffer){
@@ -92,7 +104,17 @@ async function runCode(entry, channel, interruptBuffer, outputCallback, inputCal
92104
};
93105

94106
functionsleepCallback(data){
95-
syncSleep(toObject(data).seconds*1000,channel);
107+
consttimeout=toObject(data).seconds*1000;
108+
if(!(timeout>0&&channel)){
109+
return;
110+
}
111+
constmessageId=uuidv4();
112+
try{
113+
inputCallback(messageId,{sleeping:true});
114+
readMessage(channel,messageId,{timeout});
115+
}catch(e){
116+
console.error(e);
117+
}
96118
}
97119

98120
constresult=check_entry(entry,fullInputCallback,fullOutputCallback,sleepCallback);

‎full_build.sh‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
set -eux
44

5-
poetry --version|| curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py| python
6-
source$HOME/.poetry/env
5+
poetry --version|| curl -sSL https://install.python-poetry.org| python3 -
76
poetry install
87

98
cd frontend

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp