Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

94
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!