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

Multiprocessing RuntimeError and EOFError in Python Keyboard Input Code #118

Open
ugoi opened this issue Nov 9, 2024 · 0 comments
Open

Comments

@ugoi
Copy link

ugoi commented Nov 9, 2024

Issue: RuntimeError with multiprocessing in lol.py script

Description

When running the lol.py script, an error occurs related to multiprocessing. It suggests that a process has started incorrectly before finishing its bootstrapping phase, and the usage of if __name__ == '__main__' is recommended. The issue arises from the inputs library's call to multiprocessing. Additionally, there is an AttributeError and an EOFError.

Steps to Reproduce

  1. Run lol.py with the following script:
    from inputs import get_key
    while 1:
        print("Start")
        events = get_key()
        for event in events:
            print(event.ev_type, event.code, event.state)
  2. Observe the console output for error messages.

Error Output

python3 lol.py
Start
Start
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from multiprocessing.spawn import spawn_main; spawn_main(tracker_fd=6, pipe_handle=8)
  File ".../multiprocessing/spawn.py", line 122, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File ".../multiprocessing/spawn.py", line 131, in _main
    prepare(preparation_data)
  File ".../multiprocessing/spawn.py", line 246, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File ".../multiprocessing/spawn.py", line 297, in _fixup_main_from_path
    main_content = runpy.run_path(main_path, run_name="__mp_main__")
  File ".../inputs.py", line 3661, in get_key
    return keyboard.read()
  File ".../inputs.py", line 2517, in read
    return next(iter(self))
  File ".../inputs.py", line 2471, in __iter__
    event = self._do_iter()
  File ".../inputs.py", line 2495, in _do_iter
    data = self._get_data(read_size)
  File ".../inputs.py", line 2575, in _get_data
    return self._pipe.recv_bytes()
  File ".../multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File ".../multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File ".../multiprocessing/context.py", line 289, in _Popen
    return Popen(process_obj)
  File ".../multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File ".../multiprocessing/popen_fork.py", line 20, in __init__
    self._launch(process_obj)
  File ".../multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File ".../multiprocessing/spawn.py", line 164, in get_preparation_data
    _check_not_importing_main()
  File ".../multiprocessing/spawn.py", line 140, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

Exception ignored in: <function InputDevice.__del__ at 0x...>
Traceback (most recent call last):
  File ".../inputs.py", line 2541, in __del__
  File ".../multiprocessing/process.py", line 133, in terminate
AttributeError: 'NoneType' object has no attribute 'terminate'
Traceback (most recent call last):
  File ".../lol.py", line 4, in <module>
    events = get_key()
  File ".../inputs.py", line 3661, in get_key
    return keyboard.read()
  File ".../inputs.py", line 2517, in read
    return next(iter(self))
  File ".../inputs.py", line 2471, in __iter__
    event = self._do_iter()
  File ".../inputs.py", line 2495, in _do_iter
    data = self._get_data(read_size)
  File ".../inputs.py", line 2575, in _get_data
    return self._pipe.recv_bytes()
  File ".../multiprocessing/connection.py", line 216, in recv_bytes
    buf = self._recv_bytes(maxlength)
  File ".../multiprocessing/connection.py", line 430, in _recv_bytes
    buf = self._recv(4)
  File ".../multiprocessing/connection.py", line 399, in _recv
    raise EOFError
EOFError

Environment

  • OS: macOS
  • Python Version: 3.13.0
  • Library: inputs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant