Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
Pubnub always times out in Django app

I'm building a Django app to listen to a Pubnub feed and store the messages in a database. I create a pubnub listener in my app's apps.py's AppConfig's ready() method.

Upon launching my app on Heroku, I get the really unhelpful error

2017-04-26T02:17:50.038060+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At least one process failed to exit within 30 seconds of SIGTERM
2017-04-26T02:17:50.038060+00:00 heroku[web.1]: Stopping remaining processes with SIGKILL
2017-04-26T02:17:50.134619+00:00 heroku[web.1]: Process exited with status 137

I suspect django wants to clean up the AppConfig process and is getting upset that there is a pubnub object hanging around in there. Is that the problem? How do I fix it?

I also see that (at least implicitly by example) Heroku recommends using the twisted interface. Is it bad that I'm not?

Here's the relevant code:

I created a mypubnub.py based on Pubnub's hello world example:

from pubnub.pubnub import PubNub
from pubnub.pnconfiguration import PNConfiguration
from pubnub.callbacks import SubscribeCallback


class MySubscribeCallback(SubscribeCallback):
    def presence(self, pubnub, presence):
        pass

    def status(self, pubnub, status):
        pass

    def message(self, pubnub, message):
        pass  # I'll actually do the storage here later


def create_pubnub():
    pnconf = PNConfiguration()
    pnconf.subscribe_key = 'sub-c-blargyblargblarg'
    pnconf.publish_key = 'pub-c-blargyblargblarg'
    pubnub = PubNub(pnconf)

    pubnub.add_listener(MySubscribeCallback())
    pubnub.subscribe().channels('achannel').execute()

    return pubnub

I instantiate that pubnub stuff in apps.pyfrom django.apps import AppConfig

from .mypubnub import create_pubnub

class MyAppConfig(AppConfig):
    name = 'myapp'

    def ready(self):
        pn = create_pubnub()
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Subscribing from Server is the Exception

While it is something that some PubNub customers do successfully, subscribing from your server side is typically the exception rather than the rule. It does have its proper use case though.

In this case, best practice would be to use PubNub BLOCKS to POST each message that is published from within the PubNub Network to your server rather than have your server listen on a channel or every channel to do the same.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda