There is a potential race condition in the vparser.parser.parse function and VerilogCodeParser class when multiple instances are running concurrently in the same working directory (e.g., using multiprocessing).
The default value for preprocess_output is hardcoded as 'preprocess.output':
# pyverilog/vparser/parser.py
def parse(filelist, ... preprocess_output='preprocess.output'):
codeparser = VerilogCodeParser(..., preprocess_output=preprocess_output)
# ...
class VerilogCodeParser(object):
def __init__(self, filelist, preprocess_output='preprocess.output', ...):
# ...
Impact
When multiple processes call parse() simultaneously:
- One process may overwrite the
preprocess.output file while another is reading it.
- One process may delete the file (via
os.remove) while another still needs it.
- This leads to
IOError, FileNotFoundError, or corrupted AST results.
Suggested Fix
Consider using a unique temporary filename by default using the tempfile module, or clearly document that users must provide a unique preprocess_output path when running in parallel.
import tempfile
# Use a temporary file instead of a fixed string