Skip to content

RuntimeError caused by missing main guard in multiple examples #5

@Matej-Chmel

Description

@Matej-Chmel

When running some scripts on Windows, a following RuntimeError is raised:

raise RuntimeError('''
RuntimeError:
    An attempt has been made to start a new process before the
    current process has finished its bootstrapping phase.
...

This can be fixed by introducing the main guard above the first top-level statement that is not a function or an import and indenting everything by one level after that. Here are the locations and potential solutions:

Chapter01/example1.py
if __name__ == '__main__':
    input = [i for i in range(10 ** 13, 10 ** 13 + 500)]


    # sequential
    ...
Chapter02/example1.py
if __name__ == '__main__':
    input = [i for i in range(10 ** 13, 10 ** 13 + 1000)]

    for n_workers in range(1, multiprocessing.cpu_count() + 1):
        ...
Chapter07/example1.py
if __name__ == '__main__':
    my_array = [i for i in range(20)]

    result = reduce_sum(my_array)
    print('Final result: %i.' % result)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions