[Python-bugs-list] [Bug #128475] mimetools.encode (sometimes) fails when called from a thread

noreply@sourceforge.net noreply@sourceforge.net
Fri, 19 Jan 2001 21:21:16 -0800


Bug #128475, was updated on 2001-Jan-11 11:05
Here is a current snapshot of the bug.

Project: Python
Category: Threads
Status: Open
Resolution: None
Bug Group: None
Priority: 7
Submitted by: nobody
Assigned to : tim_one
Summary: mimetools.encode (sometimes) fails when called from a thread

Details: I used this script to test.  The code of filesender.prepare_msgs
is at the end of the report.
##
import threading
import filesender

file = open('c:/windows/desktop/mp3/Aphex Twin - Bucephalus Bouncing
Ball.mp3', 'rb')

t1 = threading.Thread(target=filesender.prepare_msgs,
args=(file,'a@b.c'))

from cStringIO import StringIO
data = StringIO()
import mimetools

t2=threading.Thread(target=mimetools.encode, args=(file,data,'base64'))

import sys
if '-t1' in sys.argv:
    t1.start()
elif '-t2' in sys.argv:
    t2.start()
else:
    filesender.prepare_msgs(file, 'a@b.c')
##

Results of running it with -t1, -t2, and no options, on Windows:

C:\Python20>python test.py -t1
preparing Aphex Twin - Bucephalus Bouncing Ball.mp3

Fatal Python error: Interpreter not initialized (version mismatch?)

abnormal program termination

C:\Python20>python test.py -t1
preparing Aphex Twin - Bucephalus Bouncing Ball.mp3

Fatal Python error: Interpreter not initialized (version mismatch?)

abnormal program termination

C:\Python20>python test.py -t2
Fatal Python error: Interpreter not initialized (version mismatch?)

abnormal program termination

C:\Python20>python test.py -t2

C:\Python20>python test.py
preparing Aphex Twin - Bucephalus Bouncing Ball.mp3
encoded
got value
data length is 7807732
Encoded Aphex Twin - Bucephalus Bouncing Ball.mp3 is too large, splitting
into 2
 parts

C:\Python20>python test.py
preparing Aphex Twin - Bucephalus Bouncing Ball.mp3
encoded
got value
data length is 7807732
Encoded Aphex Twin - Bucephalus Bouncing Ball.mp3 is too large, splitting
into 2
 parts

On Linux:

wolfson@senator:~% python test.py
preparing Aphex Twin - Bucephalus Bouncing Ball.mp3
encoded
got value
data length is 7807732
Encoded Aphex Twin - Bucephalus Bouncing Ball.mp3 is too large, splitting
into 2 p
arts
wolfson@senator:~% python test.py -t1
preparing Aphex Twin - Bucephalus Bouncing Ball.mp3
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort
wolfson@senator:~% python test.py -t1
preparing Aphex Twin - Bucephalus Bouncing Ball.mp3
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort
wolfson@senator:~% python test.py -t2
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort
wolfson@senator:~% python test.py -t2
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort
wolfson@senator:~% python test.py -t2
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort

On Sun 5 it seems to always succeed.

The code for filesender.prepare_msgs:

def prepare_msgs(file, addressee):
    data = StringIO.StringIO()
    fn = getname(file)
    print 'preparing %s' % fn
    mimetools.encode(file, data, 'base64')
    print 'encoded'
    data = data.getvalue()
    print 'got value'
    datalen = len(data)
    print 'data length is %d' % datalen
    if datalen > MAX_MSG_SZ:
        numsplits = 1 + datalen / MAX_MSG_SZ
        print 'Encoded %s is too large, splitting into %d parts' %
(fn,numsplits)
        msgs = []
        for i in range(numsplits):
            thismsg, data = data[:MAX_MSG_SZ], data[MAX_MSG_SZ:]
            msgs.append(fmt_message(fn, addressee,
                                    thismsg,
                                    '(%d/%d)' % (i+1, numsplits), MSG))
        return msgs
    return [fmt_message(fn, addressee, data, '', MSG)]


Follow-Ups:

Date: 2001-Jan-19 21:21
By: tim_one

Comment:
Guido, I'm assuming that means you were able to get the small program to
fail under Linux too.  Under that assumption, I reassigned back to me.

-------------------------------------------------------

Date: 2001-Jan-19 15:10
By: gvanrossum

Comment:
I'm pretty sure it's because mimetools.encode imports base64, and doing
that in the thread somehow screws things up.  I'll look into it more later
-- or Tim can aim his debugger at it (I won't get to this before the 2.1a1
release I'm afraid).

-------------------------------------------------------

Date: 2001-Jan-19 15:04
By: gvanrossum

Comment:
Yes, fails for me too on Linux.
-------------------------------------------------------

Date: 2001-Jan-19 01:58
By: tim_one

Comment:
Guido, I took this out of the Platform-specific group because his/her test
output shows the same failures on both Windows and Linux.  I assume it
works on Sun5 for him because you have to kick a Sun OS in the groin to
make it switch threads.  [Later:  Also assigned to you so that you can try
the tiny program below on Linux] [Later:  boosted the priority too]

Anonymous submitter, sorry, but this bug report is too confusing to make
head or tail of.  Could you please whittle this down to a self-contained,
failing program that can be executed?  As is, you're showing us both code
that works (which isn't interesting) and code that doesn't (which is), and
none of it can be executed anyway (e.g., MAX_MSG_SZ isn't defined, getname
isn't defined, fmt_message isn't defined, ...).

Later:  like this:

BIGFILE = "pcbuild.opt"  # OK, it's not really big
import threading, mimetools
from cStringIO import StringIO

file1 = open(BIGFILE, 'rb') 
data1 = StringIO() 
t1 = threading.Thread(target=mimetools.encode,
                    args=(file1, data1, 'base64')) 
t1.start()

Guido, that fails for me about 1 time in 5 under Win98SE, current CVS
Python, like so:

C:\Code\python\dist\src\PCbuild>python tran.py
Fatal Python error: Interpreter not initialized (version mismatch?)

abnormal program termination

C:\Code\python\dist\src\PCbuild>

In the debug build it craps out (with about the same frequency) in
kernel32.dll (the secret bowels of Windows, which usually means running
under the debugger is futile; but I'll try that anyway when I get up
again).

-------------------------------------------------------

Date: 2001-Jan-15 11:54
By: gvanrossum

Comment:
I'm assigning this to Tim, our all-purpose Windows cleaner. :-)

Thread problems like this are notoriously hard to find, so don't hold your
breath.  Sorry!

Setting the group to platform-specific since you mention it works fine on
Sun5.
-------------------------------------------------------

Date: 2001-Jan-13 08:13
By: nobody

Comment:
I'll get you!
-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=128475&group_id=5470