Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Force fork method
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelafox committed Dec 8, 2023
1 parent a105aa6 commit f86115e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions {{cookiecutter.__src_folder_name}}/src/tests/local/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{# standard library imports #}
{% if cookiecutter.project_backend == "fastapi" %}
from multiprocessing import Process
import multiprocessing
import socket
import time
{% endif %}
{% if cookiecutter.project_backend == "flask" %}
import multiprocessing
import os
import pathlib
from multiprocessing import Process
{% endif %}
{% if cookiecutter.project_backend == "django" %}
import os
Expand Down Expand Up @@ -44,6 +44,11 @@
{% endif %}
{% endif %}

{% if cookiecutter.project_backend in ("flask", "fastapi") %}
# Set start method to "fork" to avoid issues with pickling on OSes that default to "spawn"
multiprocessing.set_start_method("fork")
{% endif %}

{% if cookiecutter.project_backend == "fastapi" %}
def wait_for_server_ready(
url: str, timeout: float = 10.0, check_interval: float = 0.5
Expand Down Expand Up @@ -130,7 +135,7 @@ def live_server_url(app_with_db):
# Start the process
hostname = ephemeral_port_reserve.LOCALHOST
free_port = ephemeral_port_reserve.reserve(hostname)
proc = Process(
proc = multiprocessing.Process(
target=run_server,
args=(
app_with_db,
Expand Down

0 comments on commit f86115e

Please sign in to comment.