"Multithreaded" Python process, queue and lock-related issues

Source: Internet
Author: User

1. Requirements

The General Service provides an agent or listener process, receives network data, and distributes it to the business processing process based on the data type.

The business processing process then processes or creates a new process thread based on the actual situation.

I have a listen_task listening process, defining the queue_from_net queue

__listen_control is responsible for putting the network data cache into queue_from_net

__listen_handle is responsible for obtaining processing data from queue_from_net, and according to the actual situation,

Create a new two __query_schedule process into a query_queue or select_queue queue handled by __query_schedule

Or close the __query_schedule process

2. Realize

__listen_control putting network data into the queue_from_net queue

__listen_handle Create or terminate the __query_schedule process according to start or stop

__query_schedule get processing from the queue

3. Questions

__query_schedule Print out Queue length before Queue_from_listen_task queue get come in

After starting the successful __query_schedule once, stop, then restart queue come in size 1, normal expected get out after Queue_from_listen_task length becomes 0

After shutting down, start again, __query_schedule print queue come in size is 2, last get did not get success queue.

The guess is that the queue lock is not released when the process terminate, resulting in a subsequent queue get not

4. Resolve

Before the terminate process, the displayed queue is released, Task_done ()

Try again, solve the problem

"Multithreaded" Python process, queue and lock-related issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.