Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure proper order of signal emission #281

Merged
merged 8 commits into from
Feb 27, 2024

Conversation

Czaki
Copy link
Contributor

@Czaki Czaki commented Feb 24, 2024

I have noticed that If some callback triggers emission of an event during an existing loop, the events may come in incorrect order, leading to a corrupted state.

I think that it is a bug, but I'm not sure if my approach to solve is correct.

Copy link

codspeed-hq bot commented Feb 24, 2024

CodSpeed Performance Report

Merging #281 will degrade performances by 10.47%

Comparing Czaki:proper_signal_order (eccef1a) with main (4aa62b0)

Summary

❌ 1 (👁 1) regressions
✅ 65 untouched benchmarks

Benchmarks breakdown

Benchmark main Czaki:proper_signal_order Change
👁 test_emit_time[setattr-50] 200.7 µs 224.1 µs -10.47%

Copy link

codecov bot commented Feb 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (4aa62b0) to head (eccef1a).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #281   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         1880      1883    +3     
=========================================
+ Hits          1880      1883    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tlambert03
Copy link
Member

minor modification suggested in Czaki#1
it's not perfect (see note about recursion error), but curious if you have any thoughts on that approach vs this current one

@tlambert03
Copy link
Member

please merge main here and make sure all the tests we've discussed are added, then ping for review

@Czaki
Copy link
Contributor Author

Czaki commented Feb 26, 2024

@tlambert03 compiled test are ending with Segfault. Did you meet something like this before:

  File "/Users/runner/work/psygnal/psygnal/tests/test_psygnal.py", line 990 in test_recursion_error

@tlambert03
Copy link
Member

no, I haven't seen that before. I can reproduce locally as well though (was just trying as you wrote), but not on main. (btw, to test locally, you can run make build, and make clean to undo ...)

@Czaki
Copy link
Contributor Author

Czaki commented Feb 26, 2024

Ok. The problem is that hatch/mypyc performs compilation in tmp directory (unlike cython that places c/cpp files in the structure of packages. So the debugger cannot find the source files.

I will try to dig, but maybe you know how to change this behavior or disable cleaning tmp

#7  0x00007ffff508f242 in CPyDef__signal___SignalInstance____run_emit_loop ()
    at /tmp/tmpcocqfl4i/build/__native_ac51d50a4f4b6d748b8c.c:37311
37311   /tmp/tmpcocqfl4i/build/__native_ac51d50a4f4b6d748b8c.c: No such file or directory

@tlambert03
Copy link
Member

good sleuthing. i also don't know, but happy to look into it if you can't find it easily

@Czaki
Copy link
Contributor Author

Czaki commented Feb 26, 2024

Im going to Warsaw Python meeting so will not be active today. Will sit to this at evening or toomorow

Comment on lines +964 to +965
if len(self._emit_queue) > RECURSION_LIMIT:
raise RecursionError
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This simulated stack is 2-3x times bigger than the original one, but maybe it not a problem.

except Exception as e:
raise EmitLoopError(cb=caller, args=args, exc=e, signal=self) from e
finally:
self._emit_queue.clear()

return None
Copy link
Member

Choose a reason for hiding this comment

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

Works for me! Thanks.

I'm not worried about the very small benchmark decreases on emit to setattr and setitem for large numbers of callbacks.

Thanks for working on this

@tlambert03 tlambert03 merged commit 4b9434e into pyapp-kit:main Feb 27, 2024
53 of 54 checks passed
@Czaki Czaki deleted the proper_signal_order branch February 27, 2024 10:00
@tlambert03 tlambert03 added the bug Something isn't working label Mar 5, 2024
@tlambert03 tlambert03 changed the title fix: ensure proper order of signal emmision fix: ensure proper order of signal emission Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

2 participants