I'm writing an web app. Users can post text, and I need to store them in my DB as well as sync them to a twitter account. 
The problem is that I'd like to response to the user immediately after inserting the message to DB, and run the "sync to twitter" process in background. 
How could I do that? Thanks
either you choose zrxq's solution, or you can do that with a thread, if you take care of two things: 

you don't tamper with objects from the main thread (be careful of iterators),
you take good care of killing your thread once the job is done.

something that would look like :

    import threading

    class TwitterThreadQueue(threading.Thread):
        queue = []

        def run(self):
            while len(self.queue!=0):
                post_on_twitter(self.queue.pop()) # here is your code to post on twitter

        def add_to_queue(self,msg):
            self.queue.append(msg)

and then you instanciate it in your code :

tweetQueue = TwitterThreadQueue()
# ...
tweetQueue.add_to_queue(message)
tweetQueue.start() # you can check if it's not already started
# ...
Sync message to twitter in background in a web application