Skip to content

Commit 78a00ef

Browse files
authored
Merge pull request freqtrade#12398 from freqtrade/fix/remove_deprecation_warning
Work around os.fork deprecation
2 parents b6bc304 + 2effa7a commit 78a00ef

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

freqtrade/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
from freqtrade.constants import DOCS_LINK
1919
from freqtrade.exceptions import ConfigurationError, FreqtradeException, OperationalException
2020
from freqtrade.loggers import setup_logging_pre
21-
from freqtrade.system import asyncio_setup, gc_set_threshold, print_version_info
21+
from freqtrade.system import (
22+
asyncio_setup,
23+
gc_set_threshold,
24+
print_version_info,
25+
set_mp_start_method,
26+
)
2227

2328

2429
logger = logging.getLogger("freqtrade")
@@ -44,6 +49,7 @@ def main(sysargv: list[str] | None = None) -> None:
4449
elif "func" in args:
4550
logger.info(f"freqtrade {__version__}")
4651
gc_set_threshold()
52+
set_mp_start_method()
4753
return_code = args["func"](args)
4854
else:
4955
# No subcommand was issued.

freqtrade/system/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from freqtrade.system.asyncio_config import asyncio_setup
44
from freqtrade.system.gc_setup import gc_set_threshold
5+
from freqtrade.system.set_mp_start_method import set_mp_start_method
56
from freqtrade.system.version_info import print_version_info
67

78

8-
__all__ = ["asyncio_setup", "gc_set_threshold", "print_version_info"]
9+
__all__ = ["asyncio_setup", "gc_set_threshold", "print_version_info", "set_mp_start_method"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from multiprocessing import get_all_start_methods, get_start_method, set_start_method
2+
3+
4+
def set_mp_start_method():
5+
"""
6+
Set multiprocessing start method to not be fork.
7+
forkserver will become the default in 3.14 - and is deprecated in 3.13
8+
"""
9+
try:
10+
sms = get_all_start_methods()
11+
if "forkserver" in sms and get_start_method(True) is None:
12+
set_start_method("forkserver")
13+
except RuntimeError:
14+
pass

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ hyperopt = [
8585
freqai = [
8686
"scikit-learn",
8787
"joblib",
88-
"catboost; 'arm' not in platform_machine",
88+
"catboost; platform_machine != 'arm'",
8989
"lightgbm",
9090
"xgboost",
9191
"tensorboard",

tests/commands/test_startup_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tests.conftest import is_arm, is_mac
55

66

7-
MAXIMUM_STARTUP_TIME = 0.7 if is_mac() and not is_arm() else 0.5
7+
MAXIMUM_STARTUP_TIME = 0.7 if is_mac() and not is_arm(True) else 0.5
88

99

1010
def test_startup_time():

tests/conftest.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from freqtrade.freqtradebot import FreqtradeBot
2222
from freqtrade.persistence import LocalTrade, Order, Trade, init_db
2323
from freqtrade.resolvers import ExchangeResolver
24+
from freqtrade.system import set_mp_start_method
2425
from freqtrade.util import dt_now, dt_ts
2526
from freqtrade.worker import Worker
2627
from tests.conftest_trades import (
@@ -500,9 +501,20 @@ def patch_gc(mocker) -> None:
500501
mocker.patch("freqtrade.main.gc_set_threshold")
501502

502503

503-
def is_arm() -> bool:
504+
@pytest.fixture(scope="session", autouse=True)
505+
def fixture_set_mp_start_method():
506+
"""
507+
Patch multiprocessing start mode globally
508+
Auto-used, runs once per session.
509+
"""
510+
set_mp_start_method()
511+
512+
513+
def is_arm(include_aarch64: bool = False) -> bool:
504514
machine = platform.machine()
505-
return "arm" in machine or "aarch64" in machine
515+
if include_aarch64:
516+
return "aarch64" in machine or "arm" in machine
517+
return "arm" in machine
506518

507519

508520
def is_mac() -> bool:

tests/freqai/test_freqai_interface.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def test_extract_data_and_train_model_Standard(
143143
("CatboostClassifierMultiTarget", "freqai_test_multimodel_classifier_strat"),
144144
],
145145
)
146+
@pytest.mark.filterwarnings(r"ignore:.*__sklearn_tags__.*:DeprecationWarning")
146147
def test_extract_data_and_train_model_MultiTargets(mocker, freqai_conf, model, strat):
147148
can_run_model(model)
148149

0 commit comments

Comments
 (0)