time module precision

Peter Hansen peter at engcorp.com
Mon Jan 10 19:19:29 EST 2005


janeaustine50 at hotmail.com wrote:
> Peter Hansen wrote:
>>_Why_ do you want to wait such brief amounts of time?
> 
> What I am trying to do is sending binary data to a serial port. Since
> the device attached to the port cannot handle a continous in-flow of
> data, I need to make an artificial tiny delay in-between data chunks(a
> few hundreds of KBs). The delay might be a few tens to hundreds of us.

I guess you've checked that your situation can't take advantage
of either hardware handshaking (e.g. RTS/CTS) or software handshaking
(Xon/Xoff) to do flow control.

Something doesn't quite feel right in your description, however,
but it could simply be because the sorts of devices we work with
are quite different.  I'm very surprised to hear about a device
that can manage to absorb *hundreds of KBs* of data without any
handshaking, and yet after that much data suddenly manages to
have a hiccup on the order of mere microseconds before it can
take more data.

Also, is your data rate so high that a few hundred microseconds
represents a noticeable delay?  I'm rarely dealing with data
rates higher than, say, 38400bps, where hundreds of KBs would take
on the order of minutes, so 100us is effectively instantaneous
in my world.

I calculate that your data rate would have to be higher than
307Mbps (a third of a gigabit per second) before 100us would
represent a large enough delay (measured in bits rather than
time) that you would be bothered by it... (defined somewhat
arbitrarily as more than 2% of the time required to send
100KB of data at your data rate).

> I'd like to make the transmission as fast as possible, uh.. well..
> reasonably fast.

I suspect it will be, if you simply do a time.sleep(0.001) and
pretend that's shorter than it really is...  since WinXP
is not a realtime OS, sometimes that could take as long as
hundreds of milliseconds, but it's very unlikely that anyone
will ever notice.

-Peter



More information about the Python-list mailing list