Skip to content

Add asyncio support#388

Merged
christiansandberg merged 13 commits intohardbyte:developfrom
christiansandberg:asyncio-support
Sep 5, 2018
Merged

Add asyncio support#388
christiansandberg merged 13 commits intohardbyte:developfrom
christiansandberg:asyncio-support

Conversation

@christiansandberg
Copy link
Copy Markdown
Collaborator

Adds support for developing asyncio applications with python-can more easily. This can be useful when implementing protocols that handles simultaneous connections to many nodes since you can write synchronous looking code without handling multiple threads and locking mechanisms.

For information I started working a year ago or so on adding native asyncio support for each interface but abandoned it since not all API's support callbacks and the performance would probably be worse than using a thread for reading messages.

@felixdivo
Copy link
Copy Markdown
Collaborator

Uhh, looks really nice!

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 11, 2018

Codecov Report

Merging #388 into develop will increase coverage by <.01%.
The diff coverage is 63.75%.

@@             Coverage Diff             @@
##           develop     #388      +/-   ##
===========================================
+ Coverage    59.25%   59.26%   +<.01%     
===========================================
  Files           55       55              
  Lines         4261     4328      +67     
===========================================
+ Hits          2525     2565      +40     
- Misses        1736     1763      +27

@felixdivo felixdivo requested a review from hardbyte August 15, 2018 14:25
@felixdivo
Copy link
Copy Markdown
Collaborator

Could you add a test for this on Python 3.4+? This could basically test the same behavior as the normal BufferedReader to cover both, right? Maybe in python-can/test/listener_test.py.

@christiansandberg
Copy link
Copy Markdown
Collaborator Author

The problem is that testing this will require statements that are not available in Python 2.7 so it won’t even be able to read the file. Not sure if that can be handled by pytest.

@felixdivo
Copy link
Copy Markdown
Collaborator

Hm, I see.

Copy link
Copy Markdown
Owner

@hardbyte hardbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

I tried it out on python 3.6 and saw messages on a vcan bus, and verified that the new test correctly gets skipped on python 2.7.

Thanks for your patience with this addition

@hardbyte hardbyte added this to the 2.3 Release milestone Aug 31, 2018
@christiansandberg christiansandberg merged commit c83ee71 into hardbyte:develop Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants