Implement filters as synchronous
See original GitHub issue- Version: 3.11.1
- Python: 2.7
- OS: linux
What was wrong?
This test is occasionally failing in Python 2:
_______________________________________________________________________________________________________ test_filter_runs_immediately ________________________________________________________________________________________________________
web3 = <web3.main.Web3 object at 0x7f08dd906b50>
def test_filter_runs_immediately(web3):
txn_filter = web3.eth.filter({})
assert txn_filter.running is None
txn_filter.watch(lambda _: _)
> assert txn_filter.running is True
E assert None is True
E + where None = <LogFilter(Thread-20, started daemon 139676051302144)>.running
txn_filter = <LogFilter(Thread-20, started daemon 139676051302144)>
web3 = <web3.main.Web3 object at 0x7f08dd906b50>
tests/core/filtering/test_filter_running_is_set_immediately.py:7: AssertionError
How can it be fixed?
The async nature of filters seems to be causing the problem. Reimplement as synchronous. If someone needs async, they can provide that in a layer on top.
Step 1
Deprecate async functionality. Both of the following APIs should start raising deprecation warnings to notify users they are going away.
Filter.watch
Filter.stop_watching
Step 2
Deprecate Filter.get
. It’s a hard to use API that isn’t intuitive.
Implement the following new APIs (names can be change).
Filter.get_new_entries()
: Calls theeth_getFilterChanges
under the hood returning only the log entries that have not been returned since the last query.Filter.get_all_entries()
: Calls theeth_getFilterLogs
under the hood returning all matching logs for the given filter.
We should consider the following convenience APIs
Filter.reset()
: Uninstalls and then reinstalls the filter.Filter.uninstall()
: Uninstalls the filter.
Step 3
Remove the deprecated APIs (this should be at least 1-2 months after the first release that the api was deprecated to give people time to upgrade.
Suggested examples for documentation
- How to wrap a filter in a thread.
- How to listen for new pending transactions.
- How to listen for newly mined blocks.
- How to manually filter for log entries (not using a contract)
- How to filter for a
Contract
instance’s log entries.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Set up default sync filters for multiple users for appointments ...
Set up default sync filters for multiple users for appointments, contacts, or tasks · Step 1. Check the current default sync filter ·...
Read more >Synchronous filtering - IEEE Xplore
Abstract—A new filtering paradigm is introduced, called syn- chronous filtering, which notably includes complex or polyphase filters as a subset.
Read more >How to use Array.prototype.filter with async? - Stack Overflow
filter is synchronous. In the previous example, I am returning none of them, I return a Promise ( all async functions are Promises...
Read more >How to use async functions with Array.filter in Javascript
Async filter with map. The async version is a bit more complicated this time and it works in two phases. The first one...
Read more >Sync Filter - Infinite Computing Systems, Inc.
Synchronization filters are usually used to limit the amount of records pulled down to a mobile device during synchronization. While they work perfectly ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The comment was before piper cleared up with those steps. I’m on the right track now. Thanks!
On Friday, October 6, 2017, Jason Carver notifications@github.com wrote:
Will be released with v4 beta, soonTM