-
Notifications
You must be signed in to change notification settings - Fork 60
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
wrong stackless.current in schedule callback #42
Comments
Original comment by Anselm Kruis (Bitbucket: akruis, GitHub: akruis): The test case is test_sched_cb.SchedulingCallbackTestCase.test2currentWithPrevAndNext, commit a70cc6e86ee1. The preliminary fix is in commit 4878b93d5294. I'm not completely sure that this the right way to fix this problem. I would prefer a solution that avoids a wrong value of current altogether. This bug renders the schedule callback almost useless, because many tasklet methods depend on the correct value of ts->st.current. |
Original comment by Kristján Valur Jónsson (Bitbucket: krisvale, GitHub: kristjanvalur): I don't think this is a bug. When switching, there is no such thing as a "current" tasklet. This is why the "old" and the "new" are provided as parameters. Whether the callback is called before or after the actual switch is in fact unspecified and an implementation detail. In facts.stackless.get_current() should probably return None in this case :) |
Original comment by Anonymous: anselm: "This bug renders the schedule callback almost useless, because many tasklet methods depend on the correct value of ts->st.current." Why do you think the schedule callback is rendered useless? We have no real notation what is current during a switch, and I fear Not sure if it is important to define the exact phase when the callback has to happen. |
Original comment by Anselm Kruis (Bitbucket: akruis, GitHub: akruis): The problem is not the value of the Python expression
can return wrong results. Without this bug being fixed, application code can't reliable use code like I don't care when the callback gets called. I don't care, if stackless.current is prev or next, but I do care that the C-language data structures are in a consistent state when Stackless executes Python code. I hope, you all agree, that this is a bug. The open question is, how to correctly fix this problem? |
Original comment by Anonymous: Whether stackless.current or ts->st.current, this is undefined during a switching callback. Code that uses stackless.current or ts->st.current during a switch is wrong code. The callback was always limited and just for monitoring use, not meant Your test case breaks this agreement. This shows me that it was an error to rely on I am sorry but do not agree that this is a bug. The bug is that we supported this in the
If this functionality should continue to exist in a fool-proof way, then a lot more needs So I propose to discard the channel-callback altogether and come up with a good |
Original comment by Anselm Kruis (Bitbucket: akruis, GitHub: akruis): Two points:
|
Original comment by Anselm Kruis (Bitbucket: akruis, GitHub: akruis): About schedule callbacks of the form "function(prev, next)" Scheduling is always a two step process: decision and switch. Now we are unhappy about the current callback, because the "current tasklet" is not well defined in our implementation but many C-functions depends on it.
The more I reason about it, the more I prefer option 2. |
Original comment by RMTEW FULL NAME (Bitbucket: rmtew, GitHub: rmtew): Saying that the documentation doesn't specify that the usage you want to get out of the scheduling callback, isn't really a valid reason to make it work for what you want. I understand you have a use case, which you and the company you work for wants to use this for, perhaps there's a way to do what you want and to leave the scheduling callback as is? |
Original comment by Anonymous: I am with Richard here: What is the real reason why you need to change this so urgently? It looks like you want to use the callback for modifications, which I would prefer to explicitly forbid and even prevent. Otherwise I cannot understand the high priority First I thought you want to (ab)use the callback to have a chance to cancel a switch. Now that your preferred second version goes completely after the switch destroyed my theory. ;-) The reason why we ask so much is a bit the fear that you want to add some constraints which are not clear now, and to force something to become defined that was not defined. That needs to have a clear advantage for the project, and making the rules Is your proposal really optimum, in every aspect that matters?
That consideration goes first, before considering a non-trivial change for no obvious reason. |
Original comment by Kristján Valur Jónsson (Bitbucket: krisvale, GitHub: kristjanvalur): On the other hand, Anselm does make a valid point: For example, assert(sys._getframe() == stackless.getcurrent().frame) would fail. Fixing this to have a consistent internal state, while not specifying what the current state is one way or the other, is probably a good thing. |
Original comment by Anonymous: Ok then let's go for it, if it has no implicit strings attached ;-) |
Original comment by Anselm Kruis (Bitbucket: akruis, GitHub: akruis): Hi Christian, my proposal to move the callback after the switch is an attempt to make a constructive reaction to your "remove that problem by removing that functionality completely". I'm fairly sure that my proposal is conceptionally clean, but I don't know, if it would fit the requirements of CCP. It is also obvious, that such a change is not trivial to implement and that it is probably to late for the current release cycle. But if we agree that a callback after the switch is conceptionally clean and that such a callback could suite our needs, then I can try to code a patch. Having a patch, we can discuss its merits and drawbacks more thoroughly. |
Original comment by Anonymous: Yes, sorry about my reaction. I agree that some consistency is worth some effort, if that consistency is needed. But again, this is about balancing:
If I would implement a better alternative, then this would be like the following, and that I would actually like:
So my proposal is to leave the logic as it is right now, but no longer call a callback, but to put the arguments somewhere. Then we have a very defined context when to pick these arguments up and run a callback. And this time, it is clean and without any constraints. If the current behavior is important for CCP, we also could keep the current code and add the "callback-after-the-switch" as another callback to install. cheers - chris |
Originally reported by: Anselm Kruis (Bitbucket: akruis, GitHub: akruis)
stackless.run() switches from the main tasklet to another tasklet T. If a schedule callback is invoked for this switch, the stackless.current is T. This is incorrect. Inspection of the code in slp_schedule_task_prepared() reveals, that Stackless calls the schedule callback before the switch.
I added a test case and I also have a preliminary fix.
The text was updated successfully, but these errors were encountered: