You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When i use yapf (just import it) in multiprocess program, it will crash with 'EOFError: Ran out of inpu',log info below:
Reproduction
yapf==0.40.2
rm -r ~/.cache/YAPF
run this python code:
import multiprocessing
def proc():
import yapf
if __name__ == "__main__":
pp=[]
for i in range(100):
p = multiprocessing.Process(target=proc)
pp.append(p)
for p in pp:
p.start()
for p in pp:
p.join()
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.
Or we can do python -c 'import yapf' before we start our multiprocess program.(for users,trick)
The text was updated successfully, but these errors were encountered:
whlook
changed the title
[Bug] [Crash] EOFError: Ran out of input when import yapf with multiprocess
[Bug] [Crash][Reproducible] EOFError: Ran out of input when import yapf with multiprocess
Feb 27, 2024
@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:
importmultiprocessingdefcleanup():
importosimportyapffromyapf_third_party._ylib2to3.pgen2.driverimport_generate_pickle_nameforiin ("Grammar.txt", "PatternGrammar.txt"):
filename=_generate_pickle_name(i)
print(f" Removing {filename}...")
os.remove(_generate_pickle_name(i))
defproc():
importyapfif__name__=="__main__":
max_parallelity=30forparallelityinrange(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= []
foriinrange(parallelity):
p=multiprocessing.Process(target=proc)
pp.append(p)
forpinpp:
p.start()
forpinpp:
p.join()
ifany(p.exitcode!=0forpinpp):
print(f"Done, race condition proven above, took {parallelity} processes.")
breakelse:
print("Done, no luck crashing this time.")
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: