Skip to content

An os.sched_param object can be dumped with pickle, but loading raises TypeError #126303

Closed
@Willy19921992

Description

@Willy19921992

Bug report

Bug description:

While working on an experiment with different scheduler priorities and the multiprocessing.Pool, I found out that using an os.sched_param object as one of the initargs parameters raised the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.12/multiprocessing/forkserver.py", line 274, in main
    code = _serve_one(child_r, fds,
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/multiprocessing/forkserver.py", line 313, in _serve_one
    code = spawn._main(child_r, parent_sentinel)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/multiprocessing/spawn.py", line 132, in _main
    self = reduction.pickle.load(from_parent)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: sched_param() takes at most 1 argument (2 given)

With a bit of investigation using the REPL, I quickly found out a simple way to reproduce the problem:

Python 3.12.7 (main, Oct  1 2024, 11:15:50) [GCC 14.2.1 20240910] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import pickle
>>> with open('schedparam', 'wb') as f:
...     pickle.dump(os.sched_param(99), f)
... 
>>> with open('schedparam', 'rb') as f:
...     pickle.load(f)
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
TypeError: sched_param() takes at most 1 argument (2 given)

The exact value used in the os.sched_param constructor doesn't affect the result. My specific use case is in Linux, where I'm trying to create a pool of processes where each one uses os.sched_setscheduler as an initializer to change their own scheduling policy to something different from the parent process and see the resulting behavior.

Im using Arch Linux with the package python3 3.12.7-1, which is the latest version as the time of writting. I have also found that this issue is also present in Pypy, if it is of any use.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions