-
Notifications
You must be signed in to change notification settings - Fork 891
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
[Bug] [Crash][Reproducible] EOFError: Ran out of input
when import yapf with multiprocess
#1204
Comments
whlook
changed the title
[Bug] [Crash]
[Bug] [Crash][Reproducible] Feb 27, 2024
EOFError: Ran out of input
when import yapf with multiprocessEOFError: Ran out of input
when import yapf with multiprocess
@whlook that's a great report, in particular the reproducer is very handy — thank you! I have a pull request coming up for this — should be auto-linked below in a minute or two —, and I would like to share my extended version of your reproducer below: import multiprocessing
def cleanup():
import os
import yapf
from yapf_third_party._ylib2to3.pgen2.driver import _generate_pickle_name
for i in ("Grammar.txt", "PatternGrammar.txt"):
filename = _generate_pickle_name(i)
print(f" Removing {filename}...")
os.remove(_generate_pickle_name(i))
def proc():
import yapf
if __name__ == "__main__":
max_parallelity = 30
for parallelity in range(2, max_parallelity + 1):
print("Cleaning up...")
cleanup_p = multiprocessing.Process(target=cleanup)
cleanup_p.start()
cleanup_p.join()
print(f"Testing for the race condition with {parallelity} processes...")
pp = []
for i in range(parallelity):
p = multiprocessing.Process(target=proc)
pp.append(p)
for p in pp:
p.start()
for p in pp:
p.join()
if any(p.exitcode != 0 for p in pp):
print(f"Done, race condition proven above, took {parallelity} processes.")
break
else:
print("Done, no luck crashing this time.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problems
Reproduction
rm -r ~/.cache/YAPF
Reason
the problem code is here:
yapf/third_party/yapf_third_party/_ylib2to3/pgen2/driver.py
Line 247 in c0908d0
When in multi process enviroment,some process will create grammar cache(when ~/.cache/YAPF not exists), before the process write to the cache file, other process will see the file exist and load it, but the cache file is empty right now , so
EOFError
will raise and the program crashed.How to fix it?
try
here(yapf/third_party/yapf_third_party/_ylib2to3/pgen2/driver.py
Line 247 in c0908d0
try
when we create the cache.python -c 'import yapf'
before we start our multiprocess program.(for users,trick)The text was updated successfully, but these errors were encountered: