serial and threads

Silke natunika at
Wed Aug 18 03:35:17 EDT 2004

Hi Peter,

I only verified this by checking it out. Here is the code

import sys
import thread           #This module provides low-level primitives for
working with multiple threads
import threading        #This module constructs higher-level threading
interfaces on top of the lower level thread module.
import serialwin32      #Python Serial Port Extension for Win32,
Linux, BSD, Jython; serial driver for win32; see
import socket           #Low-level networking interface
import binascii         #Convert between binary and ASCII

def NetworkToSerial(input):
        print "SENT: %s" % input                  # %s: if command is
not string format to string

def SerialToNetwork():
        result =
        print "RECEIVED:"
        print binascii.hexlify(result)          
s = serialwin32.Serial ()
s.port = 0                      #COM1
s.baudrate = 115200
s.databits = 8
s.timeout = None                   #None=wait forever; 0=return
immediately on read; x = x seconds

command = "0b02ff0512340000000255aa"

sthread = threading.Thread(target=NetworkToSerial(command))
rthread = threading.Thread(target=SerialToNetwork)



and it does exactly what I want it to do, so I guess it's ok...

Thank you for your help!



Peter Hansen <peter at> wrote in message news:<U9udnZz_B_2ms7_cRVn-hQ at>...
> Silke wrote:
> > I already found a solution using 'threading' instead of 'thread' :-)
> Are you positive that is really a solution?  If the original
> problem was truly because of a thread-safety issue, then it's
> most likely, I think, that it was a race condition and that
> it could very well re-appear in the future.
> The "threading" module is mostly just a higher level API on
> top of the "thread" module, so that change alone seems unlikely
> to solve the issue, unless there is code in serialwin32 specifically
> to do the proper locking when the threading module is used...
> -Peter

More information about the Python-list mailing list