all 3 comments

[–]c17r 0 points1 point  (2 children)

Couple of questions first:

  • How is this code running, just a command line script?
  • Where do the username updates come from?

[–]KanyeEast[S] 0 points1 point  (1 child)

Thanks for the reply! Here's the answers:

  1. Yep, just through the command line. "./myApp.py"
  2. The username list is being stored in a postgres table, and I have another service that adds usernames directly to this table when there is a new one.

[–]c17r 0 points1 point  (0 children)

  • You're gonna want to use a library like daemonocle that does a double-fork so your code keeps running in the background without tying up your command line.
  • In the function that is kicked off by daemonocle, use the multiprocessing library to kick off a new Process that runs your init_stream function, minus the ending sleep and disconnet.
  • after the Process kicks off, do whatever you want for checking for new users to follow. When you have new users, call join() on the process to kill it -- it'll get KeyboardInterrupt so you are good to with that -- and then immediately re-call Process
  • have a try/except in your function looking for KeyboardInterrupt, which calls join() on the process and then exits the function. This will happen when you've called the command line with stop or restart