Re: self.channel.writeHeaders(version, code, reason, headers)\nbuiltins.AttributeError: \'NoneType\' object has no attribute \'writeHeaders\'\
Jean-Paul Calderone <[email protected]> Mon, 5 Aug 2019 14:21:26 -0400
| Newsgroups | gmane.comp.python.twisted |
|---|---|
| Message-ID | <CAEeXt4OOJ1W9HsRa96czBnTMXLY+hZ9tj3nKLPGS3fD10KaF_Q@mail.gmail.com> |
--===============6797957261551852961== Content-Type: multipart/alternative; boundary="0000000000005bd87a058f62c7e3" --0000000000005bd87a058f62c7e3 Content-Type: text/plain; charset="UTF-8" On Mon, Aug 5, 2019 at 2:15 PM Waqar Khan <[email protected]> wrote: > False alarm. Seems like there are some sneaky conditions when I get the > error message. > Like before, I use to get notifyFinish error everytime. Now, it seems that > 6/10 times things are "clean" but then 4/10 times there are notifyFinish > errors. > Wondering on your suggestion. How do I ensure whether the notifyFinish > error deferred has been fired or not. > Could I have like a vanilla "HelloWorld" example? > Thanks > > You can find an example of this here - https://twistedmatrix.com/documents/current/web/howto/web-in-60/interrupted.html Jean-Paul > On Mon, Aug 5, 2019 at 2:24 AM Waqar Khan <[email protected]> wrote: > >> Hi Glyph, >> I am not sure I understand. >> >> Is there a method/variable in request which keeps a track whether >> notifyFinish has been fired.. >> So, I can do something like. >> >> if not request.hasFiredNotifyFinish: >> request.finish() >> ?? >> >> >> I have sort of able to get around this issue.. though I can't put a >> finger on what actually worked. >> Here is what I did.. First change to 19.7rc01 version.. and just fix the >> channel issue. >> >> Next self.fetch_response(request).. This is an async def.. So what I did >> was.. >> >> async def fetch_response(request): >> future = {} >> try: >> future = await some other async def.. which returns future >> except asyncio.CancelledError as e: >> print("Error..", e) >> return future >> >> I basically ended up doing this everywhere where there is async/await. >> Next, I added this: >> d.addErrback(lambda failure: failure.trap(asyncio.CancelledError)) >> >> >> So.. now.. I don't see the notifyFinish error anymore. And I am bit >> terrified not to touch anything.. :-D >> >> But, I want to try out your suggestion as that seems like a more solid >> way to handle the issue. But I am not sure I quite understand, how do I >> figure out whether notifyFinish has been called before calling finish? >> >> >> On Mon, Aug 5, 2019 at 1:56 AM Glyph <[email protected]> wrote: >> >>> >>> >>> On Aug 4, 2019, at 9:04 PM, Waqar Khan <[email protected]> wrote: >>> >>> Ah yes.. That is true.. >>> >>> If I comment out request.finish() (Here is the doc which I tried to >>> followed: >>> https://twistedmatrix.com/documents/13.0.0/web/howto/web-in-60/interrupted.html >>> ) >>> Then actually.. when I try to test out the code... (via curl or like >>> doing requests.get .. to the URI).. >>> it is just stuck.. >>> >>> >>> Yep! This makes sense; if you don't call `.finish()` *at all* then >>> your code will never tell the client that it's done. >>> >>> But if you call `.finish()` *after notifyFinish() has fired* then you >>> get that error. >>> >>> If you change your code to only call `.finish()` if the deferred >>> returned by notifyFinish() has not fired or failed yet, do you get the >>> error? It's possible that you still do, in which case, there's a bug in >>> Twisted that needs to be fixed. >>> >>> I do want to convey my thanks for the help. Really appreciate it. >>> >>> >>> Thanks for using Twisted :) >>> -g >>> >>> _______________________________________________ >>> Twisted-Python mailing list >>> [email protected] >>> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python >>> >> _______________________________________________ > Twisted-Python mailing list > [email protected] > https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > --0000000000005bd87a058f62c7e3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div dir=3D"ltr">On Mon, Aug 5, 2019 at 2:15 PM Waqar Khan= <<a href=3D"mailto:[email protected]">[email protected]</a>> wrote:<= br></div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style= =3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding= -left:1ex"><div dir=3D"ltr">False alarm. Seems like there are some sneaky c= onditions when I get the error message.<div>Like before, I use to get notif= yFinish error everytime. Now, it seems that 6/10 times=C2=A0 things are &qu= ot;clean" but then 4/10 times there are notifyFinish errors.</div><div= >Wondering on your suggestion. How do I ensure whether the notifyFinish err= or deferred has been fired or not.</div><div>Could I have like a vanilla &q= uot;HelloWorld" example?</div><div>Thanks</div></div><br></blockquote>= <div><br></div><div>You can find an example of this here -=C2=A0<a href=3D"= https://twistedmatrix.com/documents/current/web/howto/web-in-60/interrupted= .html">https://twistedmatrix.com/documents/current/web/howto/web-in-60/inte= rrupted.html</a></div><div><br></div><div>Jean-Paul</div><div>=C2=A0</div><= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex"><div class=3D"gmail_quote"= ><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Aug 5, 2019 at 2:24 AM Waqar= Khan <<a href=3D"mailto:[email protected]" target=3D"_blank">wk80333@gm= ail.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"= margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-lef= t:1ex"><div dir=3D"ltr">Hi Glyph,<div>=C2=A0 =C2=A0 I am not sure I underst= and.=C2=A0</div><div><br></div><div>Is there a method/variable in request w= hich keeps a track whether notifyFinish has been fired..</div><div>So, I ca= n do something like.</div><div><br></div><div>if not request.hasFiredNotify= Finish:</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0request.finish()</div><div>??<= /div><div><br></div><div><br></div><div>I have sort of able to get around t= his issue.. though I can't put a finger on what actually worked.=C2=A0<= /div><div>Here is what I did.. First change to 19.7rc01 version.. and just = fix the channel issue.</div><div><br></div><div>Next=C2=A0 self.fetch_respo= nse(request).. This is an async def.. So what I did was..</div><div><br></d= iv><div>async def fetch_response(request):</div><div>=C2=A0 =C2=A0 =C2=A0 = =C2=A0 future =3D {}</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 try:</div><div>= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0future =3D await some other async = def.. which returns future</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 except asy= ncio.CancelledError as e:</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0print("Error..", e)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 retu= rn future</div><div><br></div><div>I basically ended up doing this everywhe= re where there is async/await.</div><div>Next, I added this:</div><div>d.ad= dErrback(lambda failure: failure.trap(asyncio.CancelledError))=C2=A0</div><= div><br></div><div><br></div><div>So.. now.. I don't see the notifyFini= sh error anymore. And I am bit terrified not to touch anything.. :-D</div><= div><br></div><div>But, I want to try out your suggestion as that seems lik= e a more solid way to handle the issue. But I am not sure I quite understan= d, how do I figure out whether notifyFinish has been called before calling = finish?=C2=A0=C2=A0</div><div><br></div></div><br><div class=3D"gmail_quote= "><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Aug 5, 2019 at 1:56 AM Glyp= h <<a href=3D"mailto:[email protected]" target=3D"_blank">glyph@tw= istedmatrix.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" s= tyle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pad= ding-left:1ex"><div><br><div><br><blockquote type=3D"cite"><div>On Aug 4, 2= 019, at 9:04 PM, Waqar Khan <<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>> wrote:</div><br class=3D"gmail-m_7358= 7776653614432gmail-m_1609281543949452197gmail-m_966327303200188702Apple-int= erchange-newline"><div><div dir=3D"ltr">Ah yes.. That is true..<div><br></d= iv><div>If I comment out request.finish() (Here is the doc which I tried to= followed:=C2=A0<a href=3D"https://twistedmatrix.com/documents/13.0.0/web/h= owto/web-in-60/interrupted.html" target=3D"_blank">https://twistedmatrix.co= m/documents/13.0.0/web/howto/web-in-60/interrupted.html</a>)=C2=A0</div><di= v>Then actually.. when I try to test out the code... (via curl or like doin= g requests.get .. to the URI)..=C2=A0</div><div>it is just stuck..</div></d= iv></div></blockquote><div><br></div><div>Yep!=C2=A0 This makes sense; if y= ou don't call `.finish()` <i>at all</i><span style=3D"font-style:normal= ">=C2=A0then your code will never tell the client that it's done.</span= ></div><div><span style=3D"font-style:normal"><br></span></div><div>But if = you call `.finish()` <i>after notifyFinish() has fired</i><span style=3D"fo= nt-style:normal">=C2=A0then you get that error.</span></div><div><span styl= e=3D"font-style:normal"><br></span></div><div><span style=3D"font-style:nor= mal">If you change your code to only call `.finish()` if the deferred retur= ned by notifyFinish() has not fired or failed yet, do you get the error?=C2= =A0 It's possible that you still do, in which case, there's a bug i= n Twisted that needs to be fixed.</span></div><br><blockquote type=3D"cite"= ><div><div dir=3D"ltr"><div>I do want to convey my thanks for the help. Rea= lly appreciate it.</div></div></div></blockquote><br></div><div>Thanks for = using Twisted :)</div><div>-g</div><div><br></div></div>___________________= ____________________________<br> Twisted-Python mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Twist= [email protected]</a><br> <a href=3D"https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-pytho= n" rel=3D"noreferrer" target=3D"_blank">https://twistedmatrix.com/cgi-bin/m= ailman/listinfo/twisted-python</a><br> </blockquote></div> </blockquote></div> _______________________________________________<br> Twisted-Python mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Twist= [email protected]</a><br> <a href=3D"https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-pytho= n" rel=3D"noreferrer" target=3D"_blank">https://twistedmatrix.com/cgi-bin/m= ailman/listinfo/twisted-python</a><br> </blockquote></div></div> --0000000000005bd87a058f62c7e3-- --===============6797957261551852961== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVHdpc3RlZC1Q eXRob24gbWFpbGluZyBsaXN0ClR3aXN0ZWQtUHl0aG9uQHR3aXN0ZWRtYXRyaXguY29tCmh0dHBz Oi8vdHdpc3RlZG1hdHJpeC5jb20vY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL3R3aXN0ZWQtcHl0 aG9uCg== --===============6797957261551852961==--