-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Expose sched.h functions #56864
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
Comments
For fun and profit. :) |
|
2011/7/29 Amaury Forgeot d'Arc <[email protected]>:
I completely agree with you, but that's a separate issue. |
Haven't reviewed the implementation, but +1 for adding this functionality. As for splitting apart posixmodule.c, I agree that's a separate concern. Something like the _io module splitup (several C files compiled in a single extension module) looks workable. We could also consider having a separate module for this, but I can't think of any good name. "sched" is AFAIK already taken, and "scheduler" is too close to the former not to be confusing. |
I'm +0. Concerning the patch, I think that several constants ought to be |
I actually implemented this because I wanted to confine a Python process to a cpu to prevent keep it from being tossed from core to core. It made sense to bring the other scheduling functions along for the ride. |
Why didn't you use something like: $ taskset <cpu mask> python myscript.py By the way, binding a multi-threaded Python process to a single core |
2011/7/30 Charles-François Natali <[email protected]>:
Because I didn't want to type that every time I ran the script.
Indeed, that's what I was doing. |
New changeset 89e92e684b37 by Benjamin Peterson in branch 'default': |
Please also expose sched_getcpu(). |
I'm sorry, I missed this issue. I just saw its API and I have remarks on the cpu_set type:
signal.pthread_sigmask() accepts any iterable object as input, convert it to a sigset_t. For the result, it converts the new sigset_t to a classic Python set object. Is it possible to get the number of CPU to be able to convert a Python set to a cpu_set? |
sched_getaffinity returns EINVAL if the cpu_set is too small, so it should be easy enough to iterate. |
Using a Python set is fine. |
Here is a patch removing cpu_set and using sets of integers instead. |
sched_getaffinity() does not fail if the set is smaller than the Instead of this heuristic, why not simply alway using ncpus = CPU_SETSIZE? I don't know if CPU_SETSIZE is part of the standard (POSIX?). You may also use a constant size (CPU_SETSIZE) of the set used by |
Well, I've tried and it works: >>> os.sched_getaffinity(0)
{0, 1, 2, 3}
These are Linux-specific functions. |
Oh, you're right :-) I only checked ncpus (1), not the final result. sched_getaffinity(0) returns {0, 1, 2, 3, 4, 5, 6, 7} with ncpus=1 and |
+1 for Antoine's patch/approach: it's more usable and pythonic. |
As Antoine pointed out to me (and I was convinced itself, experimented with an example from man:CPU_SET(3)) the cpu_set functions work with a sets of more than CPU_SETSIZE processors. |
New changeset d6745ddbccbd by Antoine Pitrou in branch 'default': |
Ok, I've improved the default ncpus value and committed. |
New changeset fb975cb8fb45 by Victor Stinner in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: