Sunday, January 31, 2010

Flush to the Rescue, None is not zero

Well, that was quick.  (See my previous blog post about socket.makefile() in Python 3.1.1). I was sent a message to try the flush() method on the file object after attempting to write to it.  Indeed that works for both the binary io.BufferedWriter and text based io.TextIOWraper.  We usually think about using a I/O flush() method to switch between writing and reading operations, but here it is needed just to force the message to be sent instead of being held up in the buffer.

So the only question remaining is on the default value for the buffering parameter to makefile().  The following results in a buffered objects, which is what one might expect:

fd = s.makefile('w') -> buffered io.TextIOWrapper
fd = s.makefile('wb') -> buffered io.BufferedWriter

However, the default value for buffering is None, so the above two statements are equivalent to the following two, which one might think would would return an unbuffered object rather than the buffered objects returned just as above.

fd = s.makefile('w', buffering = None) -> buffered io.TextIOWrapper
fd = s.makefile('wb', buffering = None) -> buffered io.BufferedWriter

Perhaps it would be more obvious to list the default value of buffering as True, with maybe another parameter for the default buffer size.  I won't hold my breath for that change.   I'd be happy to see the documentation updated to reflect that buffering must be set to zero (buffering = 0), to get an unbuffered file object from socket.makefile()

Tricky issues with socket.makefile() in Python 3

I have been experimenting with socket.makefile()from Python 3.1.1.
The makefile() method returns a file like object for the socket so that file operations (read, readlines, write, writelines, ...) can be used to send and receive data on the socket.

I have not had much difficulty reading from the returned file object, but I don't understand the behavior when trying to write (send on the socket).  I'm hoping that someone can explain how this is supposed to work.

I find that this works for an established connection on socket s:
fd = s.makefile('wb', buffering = 0)
fd.write("This is a test message\n".encode('ascii'))

A mode of 'rwb' also works.  The object fd is of type SocketIO.

fd = s.makefile('w', buffering = 0) -> ValueError exception
fd = s.makefile('w') -> io.BufferedWriter, which does not send data.
fd = s.makefile('wb') -> io.TextIOWrapper, which does not send data.

The default value of the "buffering" parameter is None, which from my testing has a different result than 0 (zero).

So, questions:
1) Why does buffering = None result in a buffered file object?
2) Are there bugs or incomplete work with socket.makefile(), io.BufferedWriter and io.TextIOWrapper in terms of why the latter two objects are returned, but fail to send data?

If I find out the answers to these questions, I'll post them.

Monday, November 16, 2009

Linux USB Microphones

Thank you to everyone that sent information about known compatibility or lack of compatibility between USB microphones or audio mixers and Linux. I know that the list is far from complete.  But I want this to be a confirmed list, so I don't want to mention any devices that someone has not confirmed to either work or not work with Linux.

Hopefully others will send information about more USB microphones and mixers, so that the list can be more complete.

Here is the link to the list:

Thursday, November 5, 2009

Call for updated list of USB Microphones that work with Linux

I made an unexpected discovery today.  I brought my laptop running Ubuntu Linux to work that I normally leave at home.  Just for fun, I borrowed my colleague's Microsoft LifeChat LX-3000 USB microphone and plugged it in to my Ubuntu laptop.  It worked right away! This surprised me.

A few months ago when I bought my Samson C01U (which I'm very happy with),  I looked all over the Internet for information on which USB microphones work with Linux and which do not.  I found several warnings that only a few USB microphones work with Linux.  One reason for buying the Samson was that I found some web pages where others reported success using it with Linux.  This latest discovery has me wondering what other USB microphones actually do work with Linux.

If you have first hand experience with USB microphones (or USB mixers) either working or not working with Linux, please send me the make and models of those and I will collect a list and post to a web page.  Also, if you know of other web pages with this information, which is believed to be accurate, let me know. Any one have contact with any one that works directly with the Linux USB sound (ALSA) drivers?

Thursday, October 15, 2009

Online Classes are More Work, But Work Results in Learning

A recent 93-page report on online education, conducted by SRI International for the Department of Education concludes: “On average, students in online learning conditions performed better than those receiving face-to-face instruction.”  You can read a report about this from the New York Times.

I've taught a few online classes myself with mixed results.  My finding is that online classes require much more structure from the instructor and are quite a bit harder to teach well.  But from the teacher's perspective, the first time through it is much harder than subsequent semesters because much of the material may be re-used.  From the student's perspective, it is also more work.  You won't be spoon feed the material and proded along as much as in a face to face class.

In a summer online class (Python Network Programming) that I've taught twice, I find that only the most dedicated students can get through the material in the summer.  I have had to allow many incompletes with the hope of finishing it up during the fall semester.  Still quite a few end-up with a failing grade in December.   It just take self discipline and determination to complete an online class.

But I would have to say that the reported study is probably accurate for those with the determination to get through it.  If one decides to do the work, which is to read the book, read my study guide, watch my screencasts videos and do the programming assignments and, of course, the exams.  Then they will have learned quite a bit about Python Network Programming -- probably more than someone in a similar face to face class.  The bottom line is that to learn a subject well always requires work.

Wednesday, October 7, 2009

Ubuntu Got it Right with Sudo

After posting this note, I found the following tip in another blog that had the exact fix I needed  to play ShowMeDo flv videos within Firefox:

I was also able to get vlc to play video files from the desktop by adjusting its configuration.  I just told it send output to X11.  I'm not sure where the default output was going to before.  So at this point, I'm not aware of anything that is not working as desired with Ubuntu on my laptop.

I was previously wrong about Ubuntu, it is a very nice distribution.

I've been using some version of Red Hat Linux since about 1996, but decided to give the Ubuntu distribution a try on my Laptop.  The compelling thing to me about Ubuntu was that I kept seeing information on the web about how to do various things in Ubuntu.  Ubuntu seems to make it easier for others to contribute and thus has surpassed Red Hat in terms of number of packages and available information.  One company can never keep up with thousand of individuals that are all eager to contribute.

One issue that previously gave me reservations about Ubuntu was the whole thing with disabling the root account in favor of extensive use of sudo.  I have nothing against sudo, but it seemed like it might be a pain to do more extensive administrative work.  In reading Ubuntu's documentation about sudo, I discovered that sudo -i gives one a root shell, so that's not so bad.  The kicker that convinced me that someone had a good idea came while using the web browser.  As always with a new system, various add-ons needed to be installed.  Under Red Hat, the best I could do as a non-privileged user was to save an rpm file and then su to root to install it.  With Ubuntu, sudo prompts you for your password, and the add-on gets installed right then -- done.

So far, thumbs up to Ubuntu.  The only issue I'm having is that I can't play most video files -- but I'm sure in time that I'll resolve that.

Friday, October 2, 2009

Never Mind

My Background Music thing didn't work as expected.   I had the audio sounding as I want it in Audacity, but after importing the audio to Camtasia Studio, producing an avi video file, then uploading it to ShowMeDo where it was converted to an Adobe Flash flv file, the background music seemed to be mostly filtered out.

For educational videos, I don't think background music is needed.  Students can find their own background music if they want to.  My music was probably too soft for their tastes anyway.