Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
Subprocess with 'While True' ends after 3640 iterations

I have a Django app that spawns a subprocess everytime there is a database insert.

models.py

    # spawn subprocess to trigger tweepy
# output of subprocess DOES NOT log to the console.
def tweepy_tester(sender, **kwargs):
    if kwargs['created']:
        logger.error('tweepy trigger-start!')
        p = subprocess.Popen([sys.executable, "/Users/viseshprasad/PycharmProjects/Blood_e_Merry/loginsignup/tests.py"],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        logger.error('tweepy trigger-over!')


# use post_save to trigger tweepy later
post_save.connect(tweepy_tester, sender=User)

tests.py

logger = logging.getLogger(__name__)


# Create your tests here.

def for_thread():
    i = 0
    while True:
        f = open('test.txt', 'a')
        f.write('Tweepy triggered ' + str(i) + '\n')  # python will convert \n to os.linesep
        f.close()  # you can omit in most cases as the destructor will call it
        i += 1


for_thread()

The trigger happens fine but the subprocess only writes 3640 lines to the test.txt file, even though I have used while True: I am basically look for a subprocess to run non-stop after the trigger, as a separate thread and not disturbing the main thread.

The purpose : I run my app with the usual python manage.py runserver. User signs-up -> database insert -> triggers my implementation of tweepy which keeps on streaming tweets and analyzing them non-stop on a different background thread so as to not interfere with the signup process.

The above test is for this purpose. Any help is appreciated. Any alternative suggestions to implement this are also welcome.

Thanks.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda