Skip to content

Commit f296a0f

Browse files
authored
Merge pull request #761 from codeflash-ai/prevent-deadlocks-pytest
patch apscheduler when tracing
2 parents 5dffd2a + 36e3868 commit f296a0f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

codeflash/tracing/tracing_new_process.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import threading
1414
import time
1515
from collections import defaultdict
16+
from importlib.util import find_spec
1617
from pathlib import Path
1718
from typing import TYPE_CHECKING, Any, Callable, ClassVar
1819

@@ -47,6 +48,17 @@ def __init__(self, code: FakeCode, prior: FakeFrame | None) -> None:
4748
self.f_locals: dict = {}
4849

4950

51+
def patch_ap_scheduler() -> None:
52+
if find_spec("apscheduler"):
53+
import apscheduler.schedulers.background as bg
54+
import apscheduler.schedulers.blocking as bb
55+
from apscheduler.schedulers import base
56+
57+
bg.BackgroundScheduler.start = lambda _, *_a, **_k: None
58+
bb.BlockingScheduler.start = lambda _, *_a, **_k: None
59+
base.BaseScheduler.add_job = lambda _, *_a, **_k: None
60+
61+
5062
# Debug this file by simply adding print statements. This file is not meant to be debugged by the debugger.
5163
class Tracer:
5264
"""Use this class as a 'with' context manager to trace a function call.
@@ -820,6 +832,7 @@ def runctx(self, cmd: str, global_vars: dict[str, Any], local_vars: dict[str, An
820832
if __name__ == "__main__":
821833
args_dict = json.loads(sys.argv[-1])
822834
sys.argv = sys.argv[1:-1]
835+
patch_ap_scheduler()
823836
if args_dict["module"]:
824837
import runpy
825838

codeflash/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# These version placeholders will be replaced by uv-dynamic-versioning during build.
2-
__version__ = "0.17.0"
2+
__version__ = "0.16.7.post46.dev0+444ff121"

0 commit comments

Comments
 (0)