classification
Title: Remove assertion-based checking in multiprocessing
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.3, Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jnoller, pitrou, vladris
Priority: normal Keywords: patch

Created on 2009-01-19 16:32 by jnoller, last changed 2011-10-02 23:37 by vladris.

Files
File name Uploaded Description Edit
issue5001.diff vladris, 2011-10-02 20:43 Refactored asserts review
issue5001_v2.diff vladris, 2011-10-02 23:37 Second iteration review
Messages (6)
msg80192 - (view) Author: Jesse Noller (jnoller) * (Python committer) Date: 2009-01-19 16:32
Right now, the multiprocessing code is littered with statements like:

        assert self._popen is None, 'cannot start a process twice'
        assert self._parent_pid == os.getpid(), \
               'can only start a process object created by current 
process'
        assert not _current_process._daemonic, \
               'daemonic processes are not allowed to have children'

These will obviously be stripped out if running in optimized mode - 
however its not cool to rely on these anyway, the code should be 
refactored to proper checks, e.g.:

    if not hasattr(lock, 'acquire'):
        raise AttributeError("'%r' has no method 'acquire'" % lock)
msg112140 - (view) Author: Mark Lawrence (BreamoreBoy) Date: 2010-07-31 11:39
@Jesse: could you provide a patch that addresses this issue?
msg112149 - (view) Author: Jesse Noller (jnoller) * (Python committer) Date: 2010-07-31 13:07
@Mark Yeah - I'm the current multiprocessing maintainer. If I fix it, I'll just commit it :) I filed this as a to do against myself.
msg144780 - (view) Author: Vlad Riscutia (vladris) Date: 2011-10-02 20:43
I attached a patch which replaces all asserts with checks that raise exceptions. I used my judgement in determining exception types but I might have been off in some places. Also, this patch replaces ALL asserts. It is possible that some of the internal functions should be kept using asserts but I am not familiar enough with the module to say which. I figured I'd better do the whole thing than reviewers can say where lines should be reverted to asserts.
msg144781 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-10-02 21:26
Thank you. I've attached some comments, click on the "review" link to read them.
msg144795 - (view) Author: Vlad Riscutia (vladris) Date: 2011-10-02 23:37
Thanks for the quick review! I attached second iteration addressing feedback + changed all occurrences of checks like "type(x) is y" to "isinstance(x, y)".

I would appreciate a second look because this patch has many small changes and even though I ran full test suit which passed, I'm afraid I made a typo somewhere :)
History
Date User Action Args
2011-10-02 23:37:30vladrissetfiles: + issue5001_v2.diff

messages: + msg144795
2011-10-02 21:26:26pitrousetversions: + Python 3.3, - Python 3.1
nosy: + pitrou, - BreamoreBoy
messages: + msg144781

assignee: jnoller ->
stage: needs patch -> patch review
2011-10-02 20:43:49vladrissetfiles: + issue5001.diff

nosy: + vladris
messages: + msg144780

keywords: + patch
2010-07-31 13:07:06jnollersetmessages: + msg112149
2010-07-31 11:39:07BreamoreBoysetversions: + Python 3.2
nosy: + BreamoreBoy

messages: + msg112140

stage: needs patch
2009-01-22 19:22:11jnollerlinkissue3273 superseder
2009-01-19 16:32:42jnollercreate