2

For my application, a need a function that records an Ethernet Frame every 1us. Is it possible to do it with python/threading ?

The maximum delay I got with threading.Timer is close to 10ms.

Izalion
  • 708
  • 4
  • 11
  • What do you mean by "records an Ethernet Frame every 1us"? Do you want to measure the exact time between frames, or do something every 1 microsecond, or record ethernet frames which are expected to come in every microsecond, or...? – Sneftel Oct 07 '19 at 15:01
  • I would say you need to start a `multiprocessing` `Process` which has a tight loop. Whether you could ever ensure that it could do something 'every uS' is doubtful. I would say that any type of event would have too much overhead. – quamrana Oct 07 '19 at 15:10
  • @Sneftel, thank you for your reply. Actually, the third option: record ethernet frames which are exptected to come every 1us. – Izalion Oct 09 '19 at 06:51

1 Answers1

5

No.

1µs is well below the the granularity regular operating systems offer, which is usually measured in milliseconds (i.e. thousands of µs). See this answer for a discussion about Linux time slices as well as this one.

Needless to say, if the operating system cannot offer such granularity, then there's no hope for anything running in user space.

If you actually need µs level precision, you need to be looking at real-time systems. And since you have the ethernet tag in your question, you might also want to look at network processors.

Malt
  • 28,965
  • 9
  • 65
  • 105