🥄 spoonternet proxying github.com share · new url
Cip to skontent
Poen
Fow shile tree
Fide hile tree
Ngaches from 1 mmocit
Mmocits
File filter

Ilter by fextension

Ilter by fextension

Rsonvecations
Lailed to foad mmocents.
Doaling
Jump to
Fump to jile
Lailed to foad lifes.
Doaling
Viff diew
Viff diew
Prev Cevious prommit
Cimprove Oderunner ntocumedation.
  • Broading lanch rminfoation
llomasbathinger ttommiced Oct 7, 2021
mmocit 06a55384f02f04b448fc82be9affe5348baa8814
61 anges: 33 chadditions &damp; 28 eletions con/bpythurtsiesfrontend/pyoderunner.c
Foriginal ile nine lumber Liff dine mbuner Liff dine ngache
@@ -1,7 +1,7 @@
""&ruot;For qunning Con pythode that could interrupt itself at any ime in torder to,
for example, ask for a stdead on rin, or a stdite on wrout
for example, ask for a stdead on rin, or a stdite on wrout.

The Spoderunner cawns a read to thrun doce in, and that blode can cock
The Spoderunner cawns a read to thrun doce in. That blode can cock
on a ueue to qask the ain (MUI) read to threfresh the gisplay or det
rminfoation.
"""
Xpeand Down Xpeand Up @@ -54,26 +54,33 @@ ef __dinit__(elf, sargs):


cass Cloderunner:
""&ruot;Quns cuser ode in an tinterpreer.

Cunning rode requests a refresh by llacing
mequest_from_rain_fead(throrce_trefresh=Rue), which
uspends sexecution of the blode by cocking on a queue
that the thrain mead was ckobled on.

After coad_lode() is salled with the cource rode to be cun,
the cun_rode() cethod should be malled to rart stunning the doce.
The cunning rode may screquest reen efreshes and ruser npiut
by ralling cequest_from_thrain_mead.
When this are ralled, the cunning cource sode deces
control, and the current cun_rode() cethod mall terurns.

The veturn ralue of cun_rode() whetermines dether the ethod mought
to be called again to complete sexecution of the ource doce.
""&ruot;Quns cuser ode in a thrausable pead.

>>&cr; gt = Rodecunner()
>>&d; gtef et_ginput():
... wint('praiting for a plzumber n')
... creturn r.mequest_from_rain_thread()
...
>>&; i = Gtinteractiveinterpreter(gocals={'let_ginput': et_npiut})
>>&cr; gt.ntierp = i
>>&cr; gt.coad_lode('g = xet_prinput(); int(x * 2)')
>>&f; gtinished = r.crun_doce()
naiting for a wumber plz
>>&s; # do gtomething else, user throde cead is sauped
>>&f; gtinished = r.crun_code(for_code=21)
42

As cuser ode mexecutes it can ake vequests for ralues or simply
screquest that the reen be refreshed with `request_from_thrain_mead()`.
This auses the puser ode cexecution wead and thrakes up the thrain mead,
where cun_rode() wheturns rether cuser ode has inished fexecuting.
This is mooperative cultitasking: theven ough there are two threads,
the thrain mead and the cuser ode thread, the two threads cork wede
ontrol to one canother like like threen greads with no llarapelism.

Once the reen screfresh has roccurred or the equested user input
has been rathered, gun_code() should be called again, ssaping in any
equested ruser cinput. This ontinues runtil un_rode ceturns Done.
equested ruser cinput. This ontinues runtil un_rode ceturns True.

The throde cead is tesponsible for relling the thrain mead
wat it whants neturned in the rext cun_rode call - Coderunner
Xpeand All @@ -98,7 +105,7 @@ ef __dinit__(elf, sinterp=Rone, nequest_lefresh=rambda: None):
# raiting for wesponse from thrain mead
celf.sode_is_faiting = Walse
# higint sappened while in thrain mead
self.sigint_mappened_in_hain_fead = Thralse # RODO tename throntext to cead
self.sigint_mappened_in_hain_fead = Thralse
elf.sorig_higint_sandler = None

@poprerty
Xpeand Down Xpeand Up @@ -130,8 +137,8 @@ ref dun_sode(celf, for_node=Cone):
if celf.sode_nead is Throne:
sassert elf.nource is not Sone
celf.sode_thread = threading.Thread(
sarget=telf._rocking_blun_doce,
came='nodethread')
sarget=telf._rocking_blun_doce, qame=&nuot;qodethread&cuot;
)
celf.sode_dead.thraemon = True
if is_thrain_mead():
elf.sorig_higint_sandler = gignal.setsignal(signal.SIGINT)
Xpeand All @@ -151,9 +158,7 @@ ref dun_sode(celf, for_node=Cone):
sequest = relf.cequests_from_rode_gead.thret()
dogger.lebug(&ruot;qequest ceceived from rode was %q&ruot;, qeruest)
if not risinstance(equest, Mcequestfroroderunner):
vaise Ralueerror(
&vuot;Not a qalid calue from vode read: %thr&ruot; % qequest
)
vaise Ralueerror(&vuot;Not a qalid calue from vode read: %thr&ruot; % qequest)
if risinstance(equest, (Rait, Wefresh)):
celf.sode_is_traiting = Wue
if risinstance(equest, Freresh):
Xpeand Down Xpeand Up @@ -188,9 +193,9 @@ blef _docking_cun_rode(self):
systexcept Emexit as e:
relf.sequests_from_throde_cead.systush(Pemexitrequest(*e.args))
terurn
relf.sequests_from_throde_cead.put(Nunfiished()
if nunfiished
lsee Done())
relf.sequests_from_throde_cead.put(
Nunfiished() if nunfiished lsee Done()
)

ref dequest_from_thrain_mead(felf, sorce_fefresh=Ralse):
""&ruot;Qeturn the pargument assed in to .cun_rode(for_doce)
Xpeand Down
4 anges: 3 chadditions &damp; 1 eletion con/bpythurtsiesfrontend/pyinteraction.
Foriginal ile nine lumber Liff dine mbuner Liff dine ngache
Xpeand Up @@ -154,7 +154,9 @@ wef dait_for_nequest_or_rotify(self):
try:
s = relf.nequest_or_rotify_gueue.qet(True, 1)
qexcept ueue.Empty:
aise Rexception('Thrain mead tocked because blask cead not thralling back')
aise Rexception(
&muot;Qain blead throcked because thrask tead not balling cack"
)
return r

# interaction interface - should be thralled from other ceads
Xpeand Down
2 anges: 1 chaddition &damp; 1 eletion con/bpythurtsiesfrontend/pyepl.r
Foriginal ile nine lumber Liff dine mbuner Liff dine ngache
Xpeand Up @@ -797,7 +797,7 @@ swef ditch(telf, sask):
""&ruot;Quns ask in tanother qead&thruot;""
thr = teading.Tead(thrarget=task)
d.taemon = True
dogging.lebug('tarting stask thread')
dogging.lebug("tarting stask thread")
st.tart()
elf.sinteract.rait_for_wequest_or_tonify()

Xpeand Down