Re: self.channel.writeHeaders(version, code, reason, headers)\nbuiltins.AttributeError: \'NoneType\' object has no attribute \'writeHeaders\'\
Waqar Khan <[email protected]> Mon, 5 Aug 2019 14:15:28 -0400
| Newsgroups | gmane.comp.python.twisted |
|---|---|
| Message-ID | <CAJuJkHPZTS7u65G6DrMVk9umaPwqzmgZvPkwCC3=NSX-_T3pUg@mail.gmail.com> |
--===============6986001463878219538== Content-Type: multipart/alternative; boundary="000000000000fff6cf058f62b133" --000000000000fff6cf058f62b133 Content-Type: text/plain; charset="UTF-8" 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 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 >> > --000000000000fff6cf058f62b133 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">False alarm. Seems like there are some sneaky conditions w= hen I get the error message.<div>Like before, I use to get notifyFinish err= or everytime. Now, it seems that 6/10 times=C2=A0 things are "clean&qu= ot; but then 4/10 times there are notifyFinish errors.</div><div>Wondering = on your suggestion. How do I ensure whether the notifyFinish error deferred= has been fired or not.</div><div>Could I have like a vanilla "HelloWo= rld" example?</div><div>Thanks</div></div><br><div class=3D"gmail_quot= e"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Aug 5, 2019 at 2:24 AM Waq= ar Khan <<a href=3D"mailto:[email protected]">[email protected]</a>> = wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0= px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir= =3D"ltr">Hi Glyph,<div>=C2=A0 =C2=A0 I am not sure I understand.=C2=A0</div= ><div><br></div><div>Is there a method/variable in request which keeps a tr= ack whether notifyFinish has been fired..</div><div>So, I can do something = like.</div><div><br></div><div>if not request.hasFiredNotifyFinish:</div><d= iv>=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 this issue.. tho= ugh 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_response(request).. = This is an async def.. So what I did was..</div><div><br></div><div>async d= ef 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 re= turns future</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 except asyncio.Cancelled= Error 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 return future</div>= <div><br></div><div>I basically ended up doing this everywhere where there = is async/await.</div><div>Next, I added this:</div><div>d.addErrback(lambda= failure: failure.trap(asyncio.CancelledError))=C2=A0</div><div><br></div><= div><br></div><div>So.. now.. I don't see the notifyFinish error anymor= e. 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 like a more solid = way to handle the issue. But I am not sure I quite understand, how do I fig= ure 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 Glyph <<a href= =3D"mailto:[email protected]" target=3D"_blank">[email protected]= om</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margi= n:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex= "><div><br><div><br><blockquote type=3D"cite"><div>On Aug 4, 2019, at 9:04 = PM, Waqar Khan <<a href=3D"mailto:[email protected]" target=3D"_blank">w= [email protected]</a>> wrote:</div><br class=3D"gmail-m_16092815439494521= 97gmail-m_966327303200188702Apple-interchange-newline"><div><div dir=3D"ltr= ">Ah yes.. That is true..<div><br></div><div>If I comment out request.finis= h() (Here is the doc which I tried to followed:=C2=A0<a href=3D"https://twi= stedmatrix.com/documents/13.0.0/web/howto/web-in-60/interrupted.html" targe= t=3D"_blank">https://twistedmatrix.com/documents/13.0.0/web/howto/web-in-60= /interrupted.html</a>)=C2=A0</div><div>Then actually.. when I try to test o= ut the code... (via curl or like doing requests.get .. to the URI)..=C2=A0<= /div><div>it is just stuck..</div></div></div></blockquote><div><br></div><= div>Yep!=C2=A0 This makes sense; if you don't call `.finish()` <i>at al= l</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 notifyFi= nish() has fired</i><span style=3D"font-style:normal">=C2=A0then you get th= at error.</span></div><div><span style=3D"font-style:normal"><br></span></d= iv><div><span style=3D"font-style:normal">If you change your code to only c= all `.finish()` if the deferred returned by notifyFinish() has not fired or= failed yet, do you get the error?=C2=A0 It's possible that you still d= o, in which case, there's a bug in Twisted that needs to be fixed.</spa= n></div><br><blockquote type=3D"cite"><div><div dir=3D"ltr"><div>I do want = to convey my thanks for the help. Really appreciate it.</div></div></div></= blockquote><br></div><div>Thanks for using Twisted :)</div><div>-g</div><di= v><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> --000000000000fff6cf058f62b133-- --===============6986001463878219538== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVHdpc3RlZC1Q eXRob24gbWFpbGluZyBsaXN0ClR3aXN0ZWQtUHl0aG9uQHR3aXN0ZWRtYXRyaXguY29tCmh0dHBz Oi8vdHdpc3RlZG1hdHJpeC5jb20vY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL3R3aXN0ZWQtcHl0 aG9uCg== --===============6986001463878219538==--