Skip to content

Commit d04806d

Browse files
committed
address review
1 parent b578688 commit d04806d

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

examples/virtual_can_demo.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# coding: utf-8
33

44
"""
5-
This demo creates multiple processes of Producers to spam a socketcan bus.
5+
This demo creates multiple processes of producers to spam a socketcan bus.
66
"""
77

88
from time import sleep
@@ -11,19 +11,21 @@
1111
import can
1212

1313

14-
def producer(id):
14+
def producer(id, message_count=16):
1515
"""Spam the bus with messages including the data id.
16+
1617
:param int id: the id of the thread/process
1718
"""
1819

19-
with can.ThreadSafeBus(bustype='socketcan', channel='vcan0') as bus:
20-
for i in range(16):
20+
with can.Bus(bustype='socketcan', channel='vcan0') as bus:
21+
for i in range(message_count):
2122
msg = can.Message(arbitration_id=0x0cf02200+id, data=[id, i, 0, 1, 3, 1, 4, 1])
2223
bus.send(msg)
2324
sleep(1.0)
2425

26+
print("Producer #{} finished sending {} messages".format(id, message_count))
27+
28+
2529
if __name__ == "__main__":
2630
with ProcessPoolExecutor(max_workers=4) as executor:
2731
executor.map(producer, range(5))
28-
29-
sleep(1.0)

0 commit comments

Comments
 (0)