question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 the eth_getFilterChanges under the hood returning only the log entries that have not been returned since the last query.
  • Filter.get_all_entries(): Calls the eth_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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
djrtwocommented, Oct 6, 2017

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:

@djrtwo https://github.com/djrtwo Since steps 1 & 2 involve perfect backwards compatibility, I assume you’re talking about step 3.

removing all GreenletThread … code?

Completely removing gevent support is a goal: #251 https://github.com/pipermerriam/web3.py/issues/251 . It may be possible to kill two issues with one PR.

removing all … ansyncronous related code?

My first instinct is to remove all asynchronous code. That means we should show people how to implement watch in their own projects (in new docs), but not provide the method. If we keep watch at all, we’re kind of back where we started: with an asynchronous method that people have a hard time catching errors in.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pipermerriam/web3.py/issues/294#issuecomment-334835235, or mute the thread https://github.com/notifications/unsubscribe-auth/ABXf-4VkZ6YVmcvZwsmRB-rAaaguiHlyks5spnHwgaJpZM4PRwwZ .

0reactions
carvercommented, Oct 27, 2017

Will be released with v4 beta, soonTM

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found