Re: Asynchronous responses example from documentation -- why import time??
Jason Harrison <[email protected]> Wed, 8 Aug 2018 13:44:03 -0700
| Newsgroups | gmane.comp.python.twisted.web |
|---|---|
| Message-ID | <CAHVLaBF9AqxAcQ3fgiXv_XEujc3=WQAEm-OfLJt4T7XWqgEWUA@mail.gmail.com> |
--===============1538166064263633273== Content-Type: multipart/alternative; boundary="000000000000346af30572f292c3" --000000000000346af30572f292c3 Content-Type: text/plain; charset="UTF-8" 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? > --000000000000346af30572f292c3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">I may have found it, by adding the assignment "isLeaf= =3D True" to the DelayedResponse class it also appears to work.<div>H= owever many of the examples in the documentation do not assign "isLeaf= =3D True".</div><div>Would this also explain the difference in behavi= our?</div></div><div class=3D"gmail_extra"><br clear=3D"all"><div><div clas= s=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div>-Jason</div><= div><br></div>Cell: 604 644 8611<br>Email: <a href=3D"mailto:drjasonharriso= [email protected]" target=3D"_blank">[email protected]</a><br>LinkedIn: <= a href=3D"http://www.linkedin.com/in/drjasonharrison" target=3D"_blank">htt= p://www.linkedin.com/in/drjasonharrison</a><br>Twitter: <a href=3D"http://t= witter.com/drjasonharrison" target=3D"_blank">http://twitter.com/drjasonhar= rison</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/<wbr>documents/curren= t/web/howto/<wbr>web-in-60/dynamic-content.html</a></div><div>- I changed &= quot;resource =3D DelayedResource()" to "resource =3D ClockPage()= "=C2=A0</div><div>- I changed the render_GET handler to return the Clo= ck page example output</div><div>- etc until I stopped getting a 404</div><= div>- I restarted the server many many times</div><div><br></div></div></di= v><div class=3D"gmail_extra"><div class=3D"gmail_quote"><div>I removed and = backed out every change until I got a 404, concluding it was the "impo= rt time" line.=C2=A0</div><div>Any other ideas?=C2=A0</div></div></div= ></div> </blockquote></div><br></div> --000000000000346af30572f292c3-- --===============1538166064263633273== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVHdpc3RlZC13 ZWIgbWFpbGluZyBsaXN0ClR3aXN0ZWQtd2ViQHR3aXN0ZWRtYXRyaXguY29tCmh0dHBzOi8vdHdp c3RlZG1hdHJpeC5jb20vY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL3R3aXN0ZWQtd2ViCg== --===============1538166064263633273==--