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

Printing inside a loop prints garbage on parallel=True #9545

Open
AvyChanna opened this issue Apr 24, 2024 · 2 comments
Open

Printing inside a loop prints garbage on parallel=True #9545

AvyChanna opened this issue Apr 24, 2024 · 2 comments
Labels
needtriage stale Marker label for stale issues.

Comments

@AvyChanna
Copy link

AvyChanna commented Apr 24, 2024

reproducing the issue

import numba as nb

def main():
	for i in nb.prange(1000000):
		print(i)

nb.jit(main, parallel=True)()

Without parallel, it correctly prints 1000000 lines. If I num-sort the output, I correctly get a list from 0 to n.

On adding parallel=True, it prints some garbage along with the numbers. (sometimes even omits a newline and concatenates 2 lines). This happens for nopython=True, parallel=True as well.

# flags: parallel=True
# PS C:\Users\xxxxxxxx\Desktop\workspace> python .\test.py | wc
#   1000000 1000000 7888890

# flags: <none>
# PS C:\Users\xxxxxxxx\Desktop\workspace> python .\test.py | wc
#   994614  994445 7888994

Sys info

# sys.version_info = sys.version_info(major=3, minor=12, micro=2, releaselevel='final', serial=0)
# sys.version      = '3.12.2 (tags/v3.12.2:6abddd9, Feb  6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)]'
# nb.version_info  = version_info(major=0, minor=59, patch=1, short=(0, 59), full=(0, 59, 1), string='0.59.1', tuple=('0', '59', '1'), git_revision=None)

Output:
test_parallel.log

@esc
Copy link
Member

esc commented Apr 26, 2024

could it be that print is not thread-safe?

@esc esc added the needtriage label Apr 26, 2024
Copy link

This issue is marked as stale as it has had no activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with any updates and confirm that this issue still needs to be addressed.

@github-actions github-actions bot added the stale Marker label for stale issues. label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needtriage stale Marker label for stale issues.
Projects
None yet
Development

No branches or pull requests

2 participants