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 5981541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:57:30+00:00 2026-05-22T21:57:30+00:00

I want to know the best practices followed to share a queue (resource) between

  • 0

I want to know the best practices followed to share a queue (resource) between two processes in Python. Here is a what each process is doing:

Process_1: continuously gets data (in json format) from a streaming api

Process_2: is a daemon (similar to Sander Marechal’s code) which commits data (one at a time) into a database

So, Process_1 (or Producer) puts a unit of data onto this shared resource, and Process_2 (or Consumer) will poll this shared resource for any new units of data, and store them in a DB, if any.

There are some options which came to my mind:

  • Using pickle (drawback: extra overhead of pickling and de-pickling)
  • Passing data via stdout of Process_1
    to stdin of Process_2 (drawback: none, but not sure how to implement this with a daemon)
  • Using the pool object in the multiprocessing library (drawback: not sure how to code this as one process is a daemon)

I would like an optimal solution practiced in this regard, with some code :). Thanks.

  • 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-22T21:57:31+00:00Added an answer on May 22, 2026 at 9:57 pm

    multiprocessing.pool isn’t what you want in this case – it is useful for having multiple units of work done ‘in the background’ (concurrently), not so much for managing a shared resource. Since you appear to have the format of the communications worked out, and they communicate in only one direction, what you want is a multiprocessing.Queue – the documentation has a good example of how to use it – you will want your Process_1 putting data into the Queue as needed, and Process_2 calling q.get() in an infinite loop. This will cause the Consumer to block when there is nothing to do, rather than busy-waiting as you suggest (which can waste processor cycles). The issue that this leaves is closing the daemon – possibly the best way is to have the Producer put a sentinel value at the end of the queue, to ensure that the Consumer deals with all requests. Other alternatives include things like trying to forcibly kill the process when the child exits, but this is error-prone.

    Note that this assumes that the Producer spawns the Consumer (or vice versa) – if the Consumer is a long-running daemon that can deal with multiple relatively short-lived Producers, the situation becomes quite a bit harder – there isn’t, to my knowledge, any cross-platform high-level IPC module; the most portable (and generally easiest) way to handle this may be to use the filesystem as a queue – have a spool folder somewhere that the Producers write a text file to for each request; the Consumer can then process these at its leisure – however, this isn’t without its own issues: you would need to ensure that the Consumer doesn’t try to open a half-written instruction file, that the Producers aren’t stepping on each other’s toes, and that the Producers and the Consumer agree on the ordering of requests.

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

Sidebar

Related Questions

I am creating a windows service and want to know best practices for this.
I want to know what specific problems/solutions/advices/best-practices [don't punish me for the word] are
Bascially I want to know the best way to hide/show an ASP.NET control from
As regards best practices, is there a meaningful difference between using: Double d; and
I wanna to know what best practices would be used to work with Oracle
I would like to know what are the best practices to manage fixtures of
Want to know what the stackoverflow community feels about the various free and non-free
I want to know what a virtual base class is and what it means.
I want to know what are the options to do some scripting jobs in
I want to know what exactly is the sequence of calls that occurs when

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.