File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,38 @@ with FunctionPatcher().add_patch(
156156 print (nested_function(5 )) # Output: 30
157157```
158158
159+ ## Advanced Usage
160+
161+ ### Patch for multi-process applications
162+
163+ For applications that spawn multiple processes, you must use ` ModulePatcher ` to ensure that patches are applied in each child process.
164+
165+ Use ` .pth ` file to auto-apply patches on module import in each process may be a good choice.
166+
167+ ``` python
168+ # loader.py
169+ patcher = ModulePatcher()
170+ patcher.add_patch(
171+ " foo" ,
172+ target = (
173+ " class User:" ,
174+ " age: int" ,
175+ ),
176+ content
177+ )
178+ patcher.apply()
179+
180+ # xxx-awepatch.pth
181+ # xxx-awepatch.pth must be placed in site-packages directory
182+ import loader
183+ ```
184+
185+ See Also:
186+
187+ < https://github.com/tox-dev/pre-commit-uv/blob/main/src/pre_commit_uv_patch.pth >
188+ < https://github.com/pypa/setuptools/blob/main/setup.py#L12 >
189+ < https://github.com/jawah/urllib3.future/blob/main/urllib3_future.pth >
190+
159191## Use Cases
160192
161193- ** Testing** : Mock function behavior without complex mocking frameworks
You can’t perform that action at this time.
0 commit comments