-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add an option (--stop-timeout) to allow tasks to finish running their iteration before exiting #1099
Conversation
… exiting (--task-finish-wait-time)
Codecov Report
@@ Coverage Diff @@
## master #1099 +/- ##
==========================================
+ Coverage 73.94% 74.52% +0.58%
==========================================
Files 18 18
Lines 1769 1798 +29
Branches 262 269 +7
==========================================
+ Hits 1308 1340 +32
+ Misses 398 391 -7
- Partials 63 67 +4
Continue to review full report at Codecov.
|
I think the feature makes sense. With the current implementation (if my understanding of it is correct), the runner would very often wait much longer than actually needed, since all the locust users that are currently sleeping would have to wake up, and even do an extra task execution, before raising GreenletExit. I'm wondering if it would perhaps make sense to introduce a Also I think the check for the stop condition should be done at the beginning of the TaskSet's main loop (for example here: Line 365 in 644496f interrupt() wouldn't cause the TaskSet to exit (instead another task would be executed since wait() isn't called by default after an interrupt).
|
…-finish-wait-time # Conflicts: # locust/main.py
@heyman Is there a way for me to get a reference to the actual locust instance (or task instance) from LocustRunner.stop() ? I can get a reference to the class using self.locusts[i].args[0], but I cant check the state of the instance... |
Hmm, from the look of the code: Lines 128 to 132 in d6d87b4
we don't seem to store a reference to the instance ( |
Could we just spawn the greenlet with a Locust object instead of a locust class as argument? All the tests pass, and everything seems to work if I change those lines to:
I understand that it is kind of a sneaky change, but it does seem to work, and to me it does make more sense to spawn a greenlet with a reference to an object rather than to a class anyway... (this way I can access the locust object from LocustRunners.stop() easily) |
Ah, yes! That's much better. Just make sure to update the |
…e locust object from LocustRunner.stop(),I pass the locust object to spawn() instead of the locust class.
@heyman Looks like it works now. I didnt see any need for modification in kill_locusts, but maybe I'm missing something?
I dont think that is actually necessary, now that we kill sleeping locusts. Either the locust is sleeping when stop is run, and then it will be killed immediately, or it is running, in which case we set, exit_on_end_of_iteration and it will be killed as soon as the iteration is finished (it will never get to the beginning of the main loop) |
…-finish-wait-time
I dont understand the code coverage report. There's lots of diffs in there that shouldn't be there, and merging with master didnt make any difference... |
It's definitely not super clear, but if I'm not mistaken a small change is needed. Full function for reference: Lines 144 to 161 in b1c347b
Line 154 in f7170f2
currently refers to a Locust class, and this change: Line 134 in b1c347b
changes so that |
I just pushed a test to master which I believe would fail for this PR. I think the fix should be the oneliner described in my previous comment though. You should be able to rebase on/merge master and verify. Also, I wouldn't mind renaming the variables in
Me neither. |
…-finish-wait-time
…pare the class with type(g.args[0])
Also, this line shouldn't be needed (also not from this PR, but if you want you can remove it): Line 156 in f7170f2
|
Oops, my test had a Python 2.7 incompatibility 🤦♀. Fixed now! |
I guess it was there to optimize the loop? But I agree it is not needed. |
Oh, yes, you're correct. I misinterpreted the code. It does make sense to keep it. (I missed that there were a nested loop. Sorry, about that!) |
Force push ftw :) |
Actually (unless I'm mistaken) if That won't happen if the check is at the beginning of the main loop. Also I still like the idea of using a |
…ing) Added test case with use of TaskSet.interrupt(), made sure we actually terminate when that happens.
@heyman LGTY? If you want I can file a new PR, in a new branch so that the changes get the right name (stop timeout instead of task finish wait time), and also squash the changes. |
It's nitty but I think that if you place the Line 363 in 1e6eab7
you don't need the check it in two places. Other than that (and my suggested copy for the help text) I think it looks great! I don't mind merging this PR (I changed the title of it) :). |
…ace it is really needed.
…l variables do just fine, use class variables of inner class instead of outer one)
@heyman Ready to merge, IMO :) |
Solves #1049