Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1928050
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:55:56+00:00 2026-05-17T06:55:56+00:00

so I have a handler below: class PublishHandler(BaseHandler): def post(self): message = self.get_argument(message) some_function(message)

  • 0

so I have a handler below:

class PublishHandler(BaseHandler):

    def post(self):
        message = self.get_argument("message")
        some_function(message)
        self.write("success")

The problem that I’m facing is that some_function() takes some time to execute and I would like the post request to return straight away when called and for some_function() to be executed in another thread/process if possible.

I’m using berkeley db as the database and what I’m trying to do is relatively simple.

I have a database of users each with a filter. If the filter matches the message, the server will send the message to the user. Currently I’m testing with thousands of users and hence upon each publication of a message via a post request it’s iterating through thousands of users to find a match. This is my naive implementation of doing things and hence my question. How do I do this better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:55:57+00:00Added an answer on May 17, 2026 at 6:55 am

    You might be able to accomplish this by using your IOLoop‘s add_callback method like so:

    loop.add_callback(lambda: some_function(message))
    

    Tornado will execute the callback in the next IOLoop pass, which may (I’d have to dig into Tornado’s guts to know for sure, or alternatively test it) allow the request to complete before that code gets executed.

    The drawback is that that long-running code you’ve written will still take time to execute, and this may end up blocking another request. That’s not ideal if you have a lot of these requests coming in at once.

    The more foolproof solution is to run it in a separate thread or process. The best way with Python is to use a process, due to the GIL (I’d highly recommend reading up on that if you’re not familiar with it). However, on a single-processor machine the threaded implementation will work just as fine, and may be simpler to implement.

    If you’re going the threaded route, you can build a nice “async executor” module with a mutex, a thread, and a queue. Check out the multiprocessing module if you want to go the route of using a separate process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class as outlined below: class InputReader { public: typedef void (*handler)(std::string,
Question: I have the below JavaScript handler for jQuery sortable. The problem is i
Please have a look at the code below: public class MyGridFragment extends Fragment{ Handler
I have a Handler class that looks like this: class Handler{ public $group; public
I have a message handler, which consumes from a JMS queue and that sends
i have a handler for download files like below : using System; using System.Collections.Generic;
I have a parent class and child class as mentioned below. Ext.ns(MyUi); MyUi.ParentPanel =
Hi Friends i have written an Activity like below. SplashScreen.java public class SplashScreen extends
C# 2008 I have developed the class below. I have to get the balance
Let's say I have a class Base with a single member message (String). Another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.