[Twisted-Python] Twisted hangs when using pyapns

Ni Wesley nispray at gmail.com
Tue Oct 14 19:27:18 MDT 2014


Hi,
   The code is from our partner, so currently I won't change their code
until I address this issue.
The used pyapns code is here:  https://github.com/samuraisam/pyapns
And start twisted service by command :  twistd -r epoll web
--class=pyapns.server.APNSServer --port=7077

And start twisted service by command :  twistd -r epoll web
--class=pyapns.server.APNSServer --port=7077

And here is function of our code to do push action:
def __send_push(push_app_id, org_apns_cert, device_apns_token, payload):
    """
    This method will send the actual push to the device, it will first try
to send assuming we already have
    provisioned this org cert, if it fails if will provision, this way we
don't create too many connections
    """
    pyapns.configure({'HOST': MDM_PYAPNS_HOST})
    try:
        pyapns.notify(push_app_id, device_apns_token, payload)
    except UnknownAppID as e:
        # this is an expected exception where connection to this cert is
killed or we are sending this push
        # for the first time, in this case we need to provision first and
then try notify again
        current_app.logger.info(u"Couldn't find app_id for this push, retry
")
        try:
            pyapns.provision(push_app_id, org_apns_cert, 'production')
            pyapns.notify(push_app_id, device_apns_token, payload)
        except Exception as exc:
            current_app.logger.exception(exc)
    except Exception as exc:
        current_app.logger.exception(exc)

Could you please help have a look?

Thanks.
Wesley

2014-10-15 6:38 GMT+08:00 Glyph Lefkowitz <glyph at twistedmatrix.com>:

>
> On Oct 14, 2014, at 1:06 AM, Ni Wesley <nispray at gmail.com> wrote:
>
> Hi all,
>    I don't know if here is the right place.
> I hit a problem with pyapns which is based on twisted.
>
> So, I get code from our parter and setup up env involving interacting with
> APNS for IOS pushing work.
>
> I hit the problem that twisted hangs after a while's idle, I mean, when I
> start twisted with command:
> twistd -r epoll web --class=pyapns.server.APNSServer --port=7077
>
> Then, raise an notification to IOS device by pyapns(
> https://github.com/samuraisam/pyapns),it's OK.
>
> However, if I let the system alone for a while, then, new raised
> notifications are all failed, what's more, if now I kill twisted process,
> and restart with the above command again, push operations are successful
> again.
>
> I use python2.7 and twisted 14.0.0 on Redhat6.4.
>
> So, anyone has hit this problem?
>
>
> pyapns uses threads very heavily, and so my guess would be most likely
> that you're calling a Twisted API from a non-main thread.  Without seeing
> the code it's impossible to say.
>
> There's some Twisted-based apache2-licensed APNS integration code
> available here: <
> https://trac.calendarserver.org/browser/CalendarServer/trunk/calendarserver/push/applepush.py>.
> Unfortunately it is a little bound up with internal implementation details
> of calendar server, but it's *almost* generic and it might be worth the
> effort to extract, since it will almost certainly give you more robust
> behavior than integrating pyapns and Twisted.
>
> -glyph
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>


-- 
我是nispray先生
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20141015/9da4b907/attachment-0002.html>


More information about the Twisted-Python mailing list