Can PySerial's write method be called by multiple threads?
Joel Koltner
zapwireDASHgroups at yahoo.com
Wed Aug 25 14:36:07 EDT 2010
I have a multi-threaded application where several of the threads need to write
to a serial port that's being handled by pySerial. If pySerial thread-safe in
the sense that pySerial.write behaves atomically? I.e., if thread 1 executes,
serport.write("Hello, world!") and thread 2 executes serport.write("All your
bases are belong to us!"), is it guaranteed that the output over the serial
port won't "mix" the two together (e.g., "Hello All your bases are belong to
us!, world!") ?
I looked at the source code, and the write method eventually boils down to
calling an the OS's "write" function, which presumably ends up being a call to
a C function. Given the global interpreter lock -- and particularly how C
functions can't be interrupted by the Python interpreter at all -- it sure
seems as though everything is copacetic here?
If not I can just add a queue and have everything go through it, but of course
I'd like to avoid the extra code and CPU cycles if it isn't at all necessary.
Thank you,
---Joel Koltner
More information about the Python-list
mailing list