Re: Asynchronous responses example from documentation -- why import time??
Jean-Paul Calderone <[email protected]> Thu, 9 Aug 2018 09:31:35 -0400
| Newsgroups | gmane.comp.python.twisted.web |
|---|---|
| Message-ID | <CAEeXt4M1hUiZBg26C-J3dQecKv-WtesRMdrnGC8uHnr_9o7TdA@mail.gmail.com> |
--===============3058883696086421130== Content-Type: multipart/alternative; boundary="000000000000171031057300a68a" --000000000000171031057300a68a Content-Type: text/plain; charset="UTF-8" In the code you posted, DelayedResponse is the root resource. The root resource *always* has to provide a child resource. If someone requests /foo then the child is "foo". If someone requests "/" then the child is "". isLeaf = True is a shortcut that stops traversal and uses the current resource as the requested resource. Without this, DelayedResponse must have a child or it can only produce a 404. Maybe that explains it? If there are examples in the documentation that have root resources with no children and without isLeaf = True then perhaps they are also broken and should be fixed. If you see any, please point them out. Jean-Paul On Wed, Aug 8, 2018 at 4:47 PM Jason Harrison <[email protected]> wrote: > I may have found it, by adding the assignment "isLeaf = True" to the > DelayedResponse class it also appears to work. > However many of the examples in the documentation do not assign "isLeaf = > True". > Would this also explain the difference in behaviour? > > -Jason > > Cell: 604 644 8611 > Email: [email protected] > LinkedIn: http://www.linkedin.com/in/drjasonharrison > Twitter: http://twitter.com/drjasonharrison > > On Wed, Aug 8, 2018 at 1:19 PM, Jason Harrison <[email protected]> > wrote: > >> >> On Wed, 8 Aug 2018 at 11:58 AM Jean-Paul Calderone < >>> [email protected]> wrote: >> >> One possible explanation is that it has nothing to do with import time per >>> se. Instead, *any* change to your source file would have fixed the >>> problem. This could be because you had "stale" pyc files lying around >>> (cached bytecode the interpreter *thought* was up-to-date with your >>> source >>> but was actually outdated). It could also be that your server process >>> was >>> left running and was still using your old code. Then, for some reason, >>> after you added the import time your server got the new version of the >>> code >>> (perhaps you're relying on an auto-reloader and it missed a change, for >>> example, or you just forgot to restart the server yourself). >>> >>> import time itself is definitely not a requirement for arbitrary Twisted >>> Web-based programs to return a response other than 404. >>> >>> Jean-Paul >>> >>> >> Hi Jean-Paul, >> >> I made many changes to the example in order to get it to work. So perhaps >> it's a caching issue, but I can't find any caches. Here's what I'm >> developing on: >> >> - OSX 10.13.6 >> - I'm using Sublime text, no auto reloaders afaik >> - python3 --version : Python 3.7.0 >> - pip3 list: >> >> Package Version >> -------------- ------- >> attrs 18.1.0 >> Automat 0.7.0 >> constantly 15.1.0 >> dlib 19.15.0 >> hyperlink 18.0.0 >> idna 2.7 >> incremental 17.5.0 >> numpy 1.15.0 >> pip 18.0 >> PyHamcrest 1.9.0 >> setuptools 39.2.0 >> six 1.11.0 >> Twisted 18.7.0 >> wheel 0.31.1 >> zope.interface 4.5.0 >> >> - running the server using ./asynchronous.py >> - I don't have any .pyc files in the script directory, possibly because I >> "chmod +x" the source file and included the #! at the top >> - I added logging and while the main program (setup of Twisted reactor) >> logged, the DelayedResource class did not >> - I added parts of the example at >> https://twistedmatrix.com/documents/current/web/howto/web-in-60/dynamic-content.html >> - I changed "resource = DelayedResource()" to "resource = ClockPage()" >> - I changed the render_GET handler to return the Clock page example output >> - etc until I stopped getting a 404 >> - I restarted the server many many times >> >> I removed and backed out every change until I got a 404, concluding it >> was the "import time" line. >> Any other ideas? >> > > _______________________________________________ > Twisted-web mailing list > [email protected] > https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web > --000000000000171031057300a68a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">In the code you posted, DelayedResponse is the root resour= ce.=C2=A0 The root resource <i>always</i>=C2=A0has to provide a child resou= rce.=C2=A0 If someone requests /foo then the child is "foo".=C2= =A0 If someone requests "/" then the child is "".<div><= br></div><div>isLeaf =3D True is a shortcut that stops traversal and uses t= he current resource as the requested resource.=C2=A0 Without this, DelayedR= esponse must have a child or it can only produce a 404.</div><div><br></div= ><div>Maybe that explains it?=C2=A0 If there are examples in the documentat= ion that have root resources with no children and without isLeaf =3D True t= hen perhaps they are also broken and should be fixed.=C2=A0 If you see any,= please point them out.</div><div><br></div><div>Jean-Paul</div></div><br><= div class=3D"gmail_quote"><div dir=3D"ltr">On Wed, Aug 8, 2018 at 4:47 PM J= ason Harrison <<a href=3D"mailto:[email protected]">drjasonharri= [email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_quote" sty= le=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div d= ir=3D"ltr">I may have found it, by adding the assignment "isLeaf =3D T= rue" to the DelayedResponse class it also appears to work.<div>However= many of the examples in the documentation do not assign "isLeaf =3D T= rue".</div><div>Would this also explain the difference in behaviour?</= div></div><div class=3D"gmail_extra"><br clear=3D"all"><div><div class=3D"m= _-1904781368473061538gmail_signature" data-smartmail=3D"gmail_signature"><d= iv>-Jason</div><div><br></div>Cell: 604 644 8611<br>Email: <a href=3D"mailt= o:[email protected]" target=3D"_blank">[email protected]</a= ><br>LinkedIn: <a href=3D"http://www.linkedin.com/in/drjasonharrison" targe= t=3D"_blank">http://www.linkedin.com/in/drjasonharrison</a><br>Twitter: <a = href=3D"http://twitter.com/drjasonharrison" target=3D"_blank">http://twitte= r.com/drjasonharrison</a><br></div></div> <br><div class=3D"gmail_quote">On Wed, Aug 8, 2018 at 1:19 PM, Jason Harris= on <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" targe= t=3D"_blank">[email protected]</a>></span> wrote:<br><blockquote= class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli= d;padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_extra"><br><div cl= ass=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0= px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On We= d, 8 Aug 2018 at 11:58 AM=C2=A0=C2=A0Jean-Paul Calderone <<a href=3D"mai= lto:[email protected]" target=3D"_blank">[email protected]<= /a>> wrote:=C2=A0</blockquote><blockquote class=3D"gmail_quote" style=3D= "margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-le= ft:1ex">One possible explanation is that it has nothing to do with import t= ime per<br> se.=C2=A0 Instead, *any* change to your source file would have fixed the<br= > problem.=C2=A0 This could be because you had "stale" pyc files ly= ing around<br> (cached bytecode the interpreter *thought* was up-to-date with your source<= br> but was actually outdated).=C2=A0 It could also be that your server process= was<br> left running and was still using your old code.=C2=A0 Then, for some reason= ,<br> after you added the import time your server got the new version of the code= <br> (perhaps you're relying on an auto-reloader and it missed a change, for= <br> example, or you just forgot to restart the server yourself).<br> <br> import time itself is definitely not a requirement for arbitrary Twisted<br= > Web-based programs to return a response other than 404.<br> <br> Jean-Paul<br> <br></blockquote><div><br></div><div>Hi Jean-Paul,</div><div><br></div><div= >I made many changes to the example in order to get it to work. So perhaps = it's a caching issue, but I can't find any caches. Here's what = I'm developing on:</div><div><br></div><div><div class=3D"gmail_extra" = style=3D"font-size:small;text-decoration-style:initial;text-decoration-colo= r:initial"><div class=3D"gmail_quote"><div>- OSX 10.13.6</div><div>- I'= m using Sublime text, no auto reloaders afaik</div>- python3 --version : = =C2=A0Python 3.7.0<br>- pip3 list:</div></div><blockquote style=3D"font-siz= e:small;text-decoration-style:initial;text-decoration-color:initial;margin:= 0px 0px 0px 40px;border:none;padding:0px"><div class=3D"gmail_extra"><div c= lass=3D"gmail_quote"><div><div class=3D"gmail_quote">Package=C2=A0 =C2=A0 = =C2=A0 =C2=A0 Version</div></div></div></div><div class=3D"gmail_extra"><di= v class=3D"gmail_quote"><div><div class=3D"gmail_quote">-------------- ----= ---</div></div></div></div><div class=3D"gmail_extra"><div class=3D"gmail_q= uote"><div><div class=3D"gmail_quote">attrs=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 18.1.0=C2=A0</div></div></div></div><div class=3D"gmail_extra"><div cla= ss=3D"gmail_quote"><div><div class=3D"gmail_quote">Automat=C2=A0 =C2=A0 =C2= =A0 =C2=A0 0.7.0=C2=A0=C2=A0</div></div></div></div><div class=3D"gmail_ext= ra"><div class=3D"gmail_quote"><div><div class=3D"gmail_quote">constantly= =C2=A0 =C2=A0 =C2=A015.1.0=C2=A0</div></div></div></div><div class=3D"gmail= _extra"><div class=3D"gmail_quote"><div><div class=3D"gmail_quote">dlib=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A019.15.0</div></div></div></div><div c= lass=3D"gmail_extra"><div class=3D"gmail_quote"><div><div class=3D"gmail_qu= ote">hyperlink=C2=A0 =C2=A0 =C2=A0 18.0.0=C2=A0</div></div></div></div><div= class=3D"gmail_extra"><div class=3D"gmail_quote"><div><div class=3D"gmail_= quote">idna=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A02.7=C2=A0 =C2=A0=C2=A0<= /div></div></div></div><div class=3D"gmail_extra"><div class=3D"gmail_quote= "><div><div class=3D"gmail_quote">incremental=C2=A0 =C2=A0 17.5.0=C2=A0</di= v></div></div></div><div class=3D"gmail_extra"><div class=3D"gmail_quote"><= div><div class=3D"gmail_quote">numpy=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 1.15= .0=C2=A0</div></div></div></div><div class=3D"gmail_extra"><div class=3D"gm= ail_quote"><div><div class=3D"gmail_quote">pip=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 18.0=C2=A0 =C2=A0</div></div></div></div><div class=3D"gmail_= extra"><div class=3D"gmail_quote"><div><div class=3D"gmail_quote">PyHamcres= t=C2=A0 =C2=A0 =C2=A01.9.0=C2=A0=C2=A0</div></div></div></div><div class=3D= "gmail_extra"><div class=3D"gmail_quote"><div><div class=3D"gmail_quote">se= tuptools=C2=A0 =C2=A0 =C2=A039.2.0=C2=A0</div></div></div></div><div class= =3D"gmail_extra"><div class=3D"gmail_quote"><div><div class=3D"gmail_quote"= >six=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 1.11.0=C2=A0</div></div></div= ></div><div class=3D"gmail_extra"><div class=3D"gmail_quote"><div><div clas= s=3D"gmail_quote">Twisted=C2=A0 =C2=A0 =C2=A0 =C2=A0 18.7.0=C2=A0</div></di= v></div></div><div class=3D"gmail_extra"><div class=3D"gmail_quote"><div><d= iv class=3D"gmail_quote">wheel=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0.31.1=C2= =A0</div></div></div></div><div class=3D"gmail_extra"><div class=3D"gmail_q= uote"><div><div class=3D"gmail_quote">zope.interface 4.5.0</div></div></div= ></div></blockquote><div class=3D"gmail_extra" style=3D"font-size:small;tex= t-decoration-style:initial;text-decoration-color:initial"><div class=3D"gma= il_quote"><div class=3D"gmail_quote">- running the server using ./asynchron= ous.py</div></div></div></div><div>- I don't have any .pyc files in the= script directory, possibly because I "chmod +x" the source file = and included the #! at the top<br></div><div>- I added logging and while th= e main program (setup of Twisted reactor) logged, the=C2=A0DelayedResource = class did not</div><div>- I added parts of the example at=C2=A0<a href=3D"h= ttps://twistedmatrix.com/documents/current/web/howto/web-in-60/dynamic-cont= ent.html" target=3D"_blank">https://twistedmatrix.com/documents/current/web= /howto/web-in-60/dynamic-content.html</a></div><div>- I changed "resou= rce =3D DelayedResource()" to "resource =3D ClockPage()"=C2= =A0</div><div>- I changed the render_GET handler to return the Clock page e= xample output</div><div>- etc until I stopped getting a 404</div><div>- I r= estarted the server many many times</div><div><br></div></div></div><div cl= ass=3D"gmail_extra"><div class=3D"gmail_quote"><div>I removed and backed ou= t every change until I got a 404, concluding it was the "import time&q= uot; line.=C2=A0</div><div>Any other ideas?=C2=A0</div></div></div></div> </blockquote></div><br></div> _______________________________________________<br> Twisted-web mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Twisted-= [email protected]</a><br> <a href=3D"https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" = rel=3D"noreferrer" target=3D"_blank">https://twistedmatrix.com/cgi-bin/mail= man/listinfo/twisted-web</a><br> </blockquote></div> --000000000000171031057300a68a-- --===============3058883696086421130== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVHdpc3RlZC13 ZWIgbWFpbGluZyBsaXN0ClR3aXN0ZWQtd2ViQHR3aXN0ZWRtYXRyaXguY29tCmh0dHBzOi8vdHdp c3RlZG1hdHJpeC5jb20vY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL3R3aXN0ZWQtd2ViCg== --===============3058883696086421130==--