erdewit / eventkit Goto Github PK
View Code? Open in Web Editor NEWEvent-driven data pipelines
License: BSD 2-Clause "Simplified" License
Event-driven data pipelines
License: BSD 2-Clause "Simplified" License
I came across this trying to use/debug ib-insync, but really believe it is some strange interaction of eventkit, asyncio and PyCharm, which I can not explain nor solve. Could be a PyCharm issue, could be an asyncio issue.
Can't debug ib-insync really ...
Any help is appreciated. Maybe user error ...
create an environment with at least eventkit and numpy.
create 2 liner:
echo "import eventkit; print(eventkit.__version__)" > ev.py
Works:
python ev.py
result: 0.8.9
Open PyCharm (I have Community Edition 2021.2.3 on OsX)
connect to the correct environment
Run: works: result 0.8.9
Debug: crash upon "import eventkit" with exception within exception
eventkit_pycharm_debug_crash.txt
..
The package requires a py.typed marker.
After generating stubs with stubgen, mypy reports following errors:
stubs/eventkit/ops/timing.pyi:9: error: Signature of "on_source_error" incompatible with supertype "Op" [override]
stubs/eventkit/ops/timing.pyi:9: note: Superclass:
stubs/eventkit/ops/timing.pyi:9: note: def on_source_error(self, source: Any, error: Any) -> None
stubs/eventkit/ops/timing.pyi:9: note: Subclass:
stubs/eventkit/ops/timing.pyi:9: note: def on_source_error(self, error: Any) -> None
stubs/eventkit/ops/misc.pyi:10: error: Signature of "on_source_error" incompatible with supertype "Op" [override]
stubs/eventkit/ops/misc.pyi:10: note: Superclass:
stubs/eventkit/ops/misc.pyi:10: note: def on_source_error(self, source: Any, error: Any) -> None
stubs/eventkit/ops/misc.pyi:10: note: Subclass:
stubs/eventkit/ops/misc.pyi:10: note: def on_source_error(self, error: Any) -> None
stubs/eventkit/ops/array.pyi:8: error: Return type "ArrayMin" of "min" incompatible with return type "Min" in supertype "Event" [override]
stubs/eventkit/ops/array.pyi:9: error: Return type "ArrayMax" of "max" incompatible with return type "Max" in supertype "Event" [override]
stubs/eventkit/ops/array.pyi:10: error: Signature of "sum" incompatible with supertype "Event" [override]
stubs/eventkit/ops/array.pyi:10: note: Superclass:
stubs/eventkit/ops/array.pyi:10: note: def sum(self, start: int = ...) -> Sum
stubs/eventkit/ops/array.pyi:10: note: Subclass:
stubs/eventkit/ops/array.pyi:10: note: def sum(self) -> ArraySum
stubs/eventkit/ops/array.pyi:12: error: Return type "ArrayMean" of "mean" incompatible with return type "Mean" in supertype "Event" [override]
stubs/eventkit/ops/array.pyi:14: error: Return type "ArrayAny" of "any" incompatible with return type "eventkit.ops.aggregate.Any" in supertype "Event" [override]
stubs/eventkit/ops/array.pyi:15: error: Return type "ArrayAll" of "all" incompatible with return type "All" in supertype "Event" [override]
Found 8 errors in 3 files (checked 14 source files)
Line 175 in b7f424e
This would modify the self._slots
array which I believe is a no-no. Making a copy of self._slots
would probably be sufficient. This is purely on a code-review, I have not tested it.
Hi,
Is there a way to simulate the happening of an event in a unit test?
Background: I'm using ib_insync and trying to write unit tests for functions which use the waitOnUpdate() method.
Sorry if the answer is maybe obvious, but I haven't found out how.
Thanks
I'm simply setting up a pipeline in a function:
def test():
def _setup(ev: Event, target: Callable):
ev2 = ev.map(lambda x: x * 2)
ev2 += target
async def atest():
ev = Event()
_setup(ev, print)
print('start')
ev.emit(1)
ev.emit(2)
import asyncio
asyncio.get_event_loop().run_until_complete(atest())
# asyncio.run(atest())
I'm expecting to see 2 and 4 printed but I only get 'start'.
It looks like the ev2 is lost as soon as the _setup is left, because keep_ref is False by default (and using += gives no way to change it).
So for this to work correctly I'd need to keep a reference to every single transformer in the pipeline, or I'd need to explicitly create and connect Map objects with keep_ref=True, right?
Is using weak refs by default a good idea?
Would you be open to add some additional methods on Array class? While using eventkit with ib_insync, it would be helpful to have some basic indicators built in. I'm currently missing equivalent to pandas.ewm, pandas.diff, atr, rsi, but gradually more could be added. I could take a crack at it and send a PR, the question is whether you see it as part of the package or should I just make an extension?
What is the expected behavior of the following?
from eventkit import Event
event = Event("event")
def hello():
global event
print("hello")
event += goodbye # Changing the order of this line
event -= hello # and the next changes the output.
def goodbye():
print("goodbye")
event += hello
event.emit()
event.emit()
Per the comment above, changing the order of those two lines unexpectedly changes the output. It looks to me that while the first emit() is in the middle of iterating over the event slots (line 190, see [2] below), disconnecting a listener (as in event -= hello
) causes all the slots to be rebuilt (line 157, see [1] below). Will this lead to undefined behavior? It seemed to be giving me unexpected results in more complicated situations.
Perhaps the emit for loop (line 190) should make a copy of the slots before iterating over them?
[1]
Line 157 in 8fb52fe
[2]
Line 190 in 8fb52fe
Hi,
I was developing an application which should trigger every k minutes. For developing reasons I was using the following codesnippet which worked fine.
from datetime import datetime, timedelta
timer_check = eventkit.Timerange(start=datetime.now(), step=20) ``timer_check += _on_timer_check
As soon as I change to
timer_check = eventkit.Timerange(start=datetime.now(), step=timedelta(seconds=20))
the code runs, but no event is triggered anymore, which is I believe something is not working properly.
Would be great to receive a feedback.
Event.aiter allows a skip_to_last boolean argument that, when set to True, only yields last values from the source event, skipping intermediate values since the previous yield.
The current implementation uses an asynchronous queue for the entire method, whatever the value of the skip_to_last boolean argument.
Line 322 in 71b4c60
However when skip_to_last=True, it is not necessary anymore to use a queue: simple state variables remembering the last state of the source iterator are sufficient.
This could vastly reduce the memory consumption for intensive source events emitting many values - which is exactly the optimization case skip_to_last=True was intended for.
Haven's seen any docs, examples or tests related to error handling.
There's .errors operator that should return the error stream.
I tried to use it like this (test case):
def test_error():
evt = Event()
def err():
raise ValueError()
errors = evt.map(err, ordered=False).errors()
evt()
errors.run()
but it just waits indefinitely.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.