pykka icon indicating copy to clipboard operation
pykka copied to clipboard

Delayed messages

Open fjarri opened this issue 3 years ago • 9 comments

This PR implements delayed message delivery, useful for creating event loops which can still be terminated at a moment's notice. Possibly fixes #44. Also fixes an unrelated bug in eventlet.Event that caused event.wait() to result in an AttributeError.

Supporting delay in ask/tell is pretty straightforward, but doing it for proxy() requires some additional indirection. It is in the commit by itself now, because I understand that the approach I used may be questionable; I also hasn't changed the docs/tests because there is a probability the interface will be changed. Currently one would use delayed proxies as

proxy = actor_ref.proxy(extended=True)
proxy.delayed(1).something()
proxy.delayed(2).some.attr = 1

All the introspection is only done once when proxy_base is created.

This PR has some intersection of functionality with PR #95, but is simpler and gives actors more control of the process (specifically, it is more convenient for event loop organization).

fjarri avatar Nov 02 '20 07:11 fjarri

Codecov Report

Merging #102 (50dac57) into main (ac006f7) will decrease coverage by 2.68%. The diff coverage is 84.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #102      +/-   ##
==========================================
- Coverage   94.59%   91.91%   -2.69%     
==========================================
  Files          12       12              
  Lines         481      581     +100     
==========================================
+ Hits          455      534      +79     
- Misses         26       47      +21     
Impacted Files Coverage Δ
src/pykka/_proxy.py 88.31% <77.33%> (-10.70%) :arrow_down:
src/pykka/_ref.py 98.11% <88.88%> (-1.89%) :arrow_down:
src/pykka/_actor.py 93.90% <95.12%> (-0.46%) :arrow_down:
src/pykka/_envelope.py 100.00% <100.00%> (ø)
src/pykka/_threading.py 96.42% <100.00%> (+0.20%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ac006f7...50dac57. Read the comment docs.

codecov[bot] avatar Nov 02 '20 20:11 codecov[bot]

@jodal the PR is ready for the initial review now

fjarri avatar Nov 05 '20 07:11 fjarri

My initial thought upon reading the patch is that monotonic timers should be used. Right now it looks like a collision course for problems around daylight saving time changes and leap seconds.

djmattyg007 avatar Jan 05 '21 09:01 djmattyg007

Isn't system timer always monotonic and not affected by timezones/daylight savings etc?

fjarri avatar Jan 05 '21 16:01 fjarri

If that was true there wouldn't be any point for time.monotonic() to exist. The output of time.time() abaolutely is not guaranteed to be monotonic.

djmattyg007 avatar Jan 05 '21 21:01 djmattyg007

My bad, I thought time.time() takes values from the system timer. Seems like an easy fix then?

fjarri avatar Jan 05 '21 21:01 fjarri

I should have looked this up initially:

https://docs.python.org/3/library/time.html?highlight=monotonic#time.time

While this function normally returns non-decreasing values, it can return a lower value than a previous call if the system clock has been set back between the two calls.

You definitely want time.monotonic(). I'm not sure how difficult it would be to switch everything over, but hopefully in most cases if all you're doing is diffing timestamps it should be fine.

djmattyg007 avatar Jan 05 '21 21:01 djmattyg007

@djmattyg007 , updated the PR, thanks for pointing out this problem. It was pretty easy, there were just two places where time.time() was used.

fjarri avatar Jan 09 '21 04:01 fjarri

@adamcik , thanks for the comments. I was postponing writing the docs until I'm sure @jodal is happy with the API, especially that of ActorProxy (and with the PR in general).

fjarri avatar Mar 07 '21 19:03 fjarri