This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Process is locked when try to execute Queue.put() inside
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: davin Nosy List: Guni, davin, eric.smith, pitrou, rhettinger, tim.peters, xiang.zhang
Priority: normal Keywords:

Created on 2016-08-23 08:56 by Guni, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
27833.py eric.smith, 2016-08-24 14:17
Messages (8)
msg273426 - (view) Author: Guni (Guni) Date: 2016-08-23 08:56
Hello,

When I try to put a long string (I mean longer then 65523 chars) in a queue if the put is inside in Process it's block the process and Process.Join() never execute.

Let's me give an example:
---------------
from multiprocessing import Queue, Process

def getLongString():
	s = ""
	for i in range(1, 65524):
		s += "1"
	return s

def p1(q):
	print('START')
	q.put(getLongString())
	print('END')

q = Queue()

prs1 = Process(target=p1, args=(q,))
prs1.start()
prs1.join()

print('FINISH')
----------------

##############
The result of it 65524 chars will be:
START
END
##############

##############
The result of it 65523 chars will be:
START
END
FINISH
##############
msg273566 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-08-24 14:17
Here's a slightly simplified version. I can reproduce this on Windows with 3.4.3 cygwin 32-bit and on Linux with 3.3.2 64-bit.
msg273573 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2016-08-24 15:44
Looks to me like this is what the docs are talking about when they say:

"""
As mentioned above, if a child process has put items on a queue (and it has not used JoinableQueue.cancel_join_thread), then that process will not terminate until all buffered items have been flushed to the pipe.

This means that if you try joining that process you may get a deadlock unless you are sure that all items which have been put on the queue have been consumed. Similarly, if the child process is non-daemonic then the parent process may hang on exit when it tries to join all its non-daemonic children.

Note that a queue created using a manager does not have this issue. See Programming guidelines.
"""
msg273579 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-08-24 17:18
Tim: I believe that's correct. I'm going to close this issue.

Guni: If you have more information or you feel this is an actual bug, please post it here.
msg273638 - (view) Author: Guni (Guni) Date: 2016-08-25 08:40
Hi Eric,

The reason why I still think is a actually bug is because the behaviour is not consistent. When we write code we don't exactly know how much data we will put in the queue.

If this ticket is consider as not an actual bug it means that everybody has to make a check inside the process in order to predict what behaviour will happen.

Feel free to close the ticket if you think that's a feature not a bug.

Thanks
msg273639 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-08-25 09:40
Guni, the behaviour is not consistent since your code is not that 'right'. You can not expect a not 'right' snippet to behave correctly. You can do what the programming guide says:

[1] consuming all items before join
[2] call q.cancel_join_thread
[3] ignore prs1.join since it will be automatically joined

Choose one and then the behaviour would be consistent.
msg273690 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-08-26 03:24
Davin, what are your thoughts?
msg298876 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-07-22 21:55
Indeed the simple solution here is to consume items in the queue before trying to join the process.
History
Date User Action Args
2022-04-11 14:58:35adminsetgithub: 72020
2017-07-22 21:55:07pitrousetstatus: open -> closed


messages: + msg298876
nosy: + pitrou
2016-08-26 03:24:53rhettingersetassignee: davin

messages: + msg273690
nosy: + rhettinger
2016-08-25 09:40:32xiang.zhangsetmessages: + msg273639
2016-08-25 08:40:14Gunisetstatus: closed -> open

messages: + msg273638
2016-08-24 17:18:42eric.smithsetstatus: open -> closed
resolution: not a bug
messages: + msg273579

stage: resolved
2016-08-24 15:44:20tim.peterssetnosy: + tim.peters
messages: + msg273573
2016-08-24 14:17:08eric.smithsetfiles: + 27833.py
nosy: + eric.smith
messages: + msg273566

2016-08-24 10:58:48xiang.zhangsetnosy: + xiang.zhang
2016-08-23 09:44:47xiang.zhangsetnosy: + davin
type: behavior
components: + Library (Lib)
2016-08-23 08:56:53Gunicreate