How to run python thread on only one Paste server?

How to run python thread on only one Paste server?

Postby troyan » Thu Aug 29, 2013 2:13 pm

Hello guys,

I have got little problem during developing notification functionality in Pylons-based application.
We use multi-server configuration with 4 Paste servers (with 10-threads threadpool for each server).
I decided to implement is as background thread which through scheduler runs check for notifications every minute.

in Python script I imported:

import thread, threading

and in main make_app function added following:

thread.start_new_thread(timingforalerts, (app_globals, config, )) #creates separate thread for searching pending alerts

timingforalerts() is my function which queries database for pending alerts and if any are found sends notifications through e-mail/jabber.

PROBLEM is that this thread is started on EACH server, so that means there are FOUR threads created for searching alerts. It affects that when notification is found user receives four email or four Jabber messages.

Please help me figure out how to start thread only on one server (for example only on server:main).

Configuration in development.ini looks following:

[server:main]
use = egg:Paste#http
host = 127.0.0.1
port = 5000
use_threadpool = True
threadpool_workers = 10

[server:main2]
use = egg:Paste#http
host = 127.0.0.1
port = 5001
use_threadpool = True
threadpool_workers = 10

[server:main3]
use = egg:Paste#http
host = 127.0.0.1
port = 5002
use_threadpool = True
threadpool_workers = 10

[server:main4]
use = egg:Paste#http
host = 127.0.0.1
port = 5003
use_threadpool = True
threadpool_workers = 10
troyan
 
Posts: 1
Joined: Thu Aug 29, 2013 2:12 pm

Re: How to run python thread on only one Paste server?

Postby micseydel » Fri Aug 30, 2013 1:02 am

I don't know that much about this, but I suspect that if you're using threading directly at the same time as a framework that you're either doing it wrong or should be using a framework that takes care of it for you. Also, your posts are much easier to read if they use
Code: Select all
code tags
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 923
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to Web Development

Who is online

Users browsing this forum: No registered users and 1 guest