Re: self.channel.writeHeaders(version, code, reason, headers)\nbuiltins.AttributeError: \'NoneType\' object has no attribute \'writeHeaders\'\

Waqar Khan <[email protected]> Mon, 5 Aug 2019 02:24:37 -0400
Newsgroups gmane.comp.python.twisted
Message-ID <CAJuJkHM2r+oUe-0kPEeJg1hFnOo-VgC1D8ju+gh+QudLvH_Cig@mail.gmail.com>
--===============6935428550339758205==
Content-Type: multipart/alternative; boundary="000000000000ccf2d7058f58c310"

--000000000000ccf2d7058f58c310
Content-Type: text/plain; charset="UTF-8"

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
>

--000000000000ccf2d7058f58c310
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<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 ke=
eps a track whether notifyFinish has been fired..</div><div>So, I can do so=
mething like.</div><div><br></div><div>if not request.hasFiredNotifyFinish:=
</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0request.finish()</div><div>??</div><d=
iv><br></div><div><br></div><div>I have sort of able to get around this iss=
ue.. though I can&#39;t put a finger on what actually worked.=C2=A0</div><d=
iv>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(req=
uest).. This is an async def.. So what I did was..</div><div><br></div><div=
>async def fetch_response(request):</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 f=
uture =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.. w=
hich returns future</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 except asyncio.Ca=
ncelledError as e:</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print=
(&quot;Error..&quot;, e)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return futur=
e</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&#39;t see the notifyFinish 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 like a more=
 solid way to handle the issue. But I am not sure I quite understand, how d=
o 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 Glyph &lt;<=
a href=3D"mailto:[email protected]">[email protected]</a>&gt; w=
rote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style=
=3D"overflow-wrap: break-word;"><br><div><br><blockquote type=3D"cite"><div=
>On Aug 4, 2019, at 9:04 PM, Waqar Khan &lt;<a href=3D"mailto:wk80333@gmail=
.com" target=3D"_blank">[email protected]</a>&gt; wrote:</div><br class=3D"=
gmail-m_966327303200188702Apple-interchange-newline"><div><div dir=3D"ltr">=
Ah yes.. That is true..<div><br></div><div>If I comment out request.finish(=
) (Here is the doc which I tried to followed:=C2=A0<a href=3D"https://twist=
edmatrix.com/documents/13.0.0/web/howto/web-in-60/interrupted.html" target=
=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 ou=
t 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><d=
iv>Yep!=C2=A0 This makes sense; if you don&#39;t call `.finish()` <i>at all=
</i><span style=3D"font-style:normal">=C2=A0then your code will never tell =
the client that it&#39;s done.</span></div><div><span style=3D"font-style:n=
ormal"><br></span></div><div>But if you call `.finish()` <i>after notifyFin=
ish() has fired</i><span style=3D"font-style:normal">=C2=A0then you get tha=
t error.</span></div><div><span style=3D"font-style:normal"><br></span></di=
v><div><span style=3D"font-style:normal">If you change your code to only ca=
ll `.finish()` if the deferred returned by notifyFinish() has not fired or =
failed yet, do you get the error?=C2=A0 It&#39;s possible that you still do=
, in which case, there&#39;s a bug in Twisted that needs to be fixed.</span=
></div><br><blockquote type=3D"cite"><div><div dir=3D"ltr"><div>I do want t=
o convey my thanks for the help. Really appreciate it.</div></div></div></b=
lockquote><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>

--000000000000ccf2d7058f58c310--

--===============6935428550339758205==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVHdpc3RlZC1Q
eXRob24gbWFpbGluZyBsaXN0ClR3aXN0ZWQtUHl0aG9uQHR3aXN0ZWRtYXRyaXguY29tCmh0dHBz
Oi8vdHdpc3RlZG1hdHJpeC5jb20vY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL3R3aXN0ZWQtcHl0
aG9uCg==

--===============6935428550339758205==--