You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: serverless/development/dual-mode-worker.mdx
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ In this tutorial you'll learn how to:
39
39
40
40
## Requirements
41
41
42
-
* You've [created a RunPod account](/get-started/manage-accounts).
42
+
* You've [created a Runpod account](/get-started/manage-accounts).
43
43
* You've installed [Python 3.x](https://www.python.org/downloads/) and [Docker](https://docs.docker.com/get-started/get-docker/) on your local machine and configured them for your command line.
44
44
* Basic understanding of Docker concepts and shell scripting.
-`handler.py`: Your Python script with the RunPod handler logic.
60
+
-`handler.py`: Your Python script with the Runpod handler logic.
61
61
-`start.sh`: A shell script that will be the entrypoint for your Docker container.
62
62
-`Dockerfile`: Instructions to build your Docker image.
63
63
-`requirements.txt`: A file to list Python dependencies.
@@ -105,9 +105,9 @@ Key features:
105
105
106
106
*`MODE_TO_RUN = os.getenv("MODE_TO_RUN", "pod")`: Reads the mode from an environment variable, defaulting to `pod`.
107
107
*`async def handler(event)`: Your core logic.
108
-
*`if __name__ == '__main__':`: This block controls what happens when the script is executed directly.
109
-
* In `serverless`" mode, it starts the RunPod Serverless worker.
108
+
*`if mode_to_run == "pod" ... else`: This conditional controls what happens when the script is executed directly.
110
109
* In `pod` mode, it runs a sample test call to your `handler` function, allowing for quick iteration.
110
+
* In `serverless`" mode, it starts the Runpod Serverless worker.
111
111
112
112
## Step 3: Create the `start.sh` script
113
113
@@ -214,7 +214,7 @@ sleep infinity
214
214
```
215
215
Key features:
216
216
*`case $MODE_TO_RUN in ... esac`: This structure directs the startup based on the mode.
217
-
*`serverless` mode: Executes `handler.py`, which then starts the RunPod Serverless worker. `exec` replaces the shell process with the Python process.
217
+
*`serverless` mode: Executes `handler.py`, which then starts the Runpod Serverless worker. `exec` replaces the shell process with the Python process.
218
218
*`pod` mode: Starts up the JupyterLab server for Pod development, then runs `sleep infinity` to keep the container alive so you can connect to it (e.g., via SSH or `docker exec`). You would then manually run `python /app/handler.py` inside the Pod to test your handler logic.
219
219
220
220
## Step 4: Create the `Dockerfile`
@@ -224,7 +224,7 @@ This file defines how to build your Docker image.
224
224
Add the following content to `Dockerfile`:
225
225
226
226
```dockerfile
227
-
# Use an official RunPod base image
227
+
# Use an official Runpod base image
228
228
FROM runpod/pytorch:2.0.1-py3.10-cuda11.8.0-devel-ubuntu22.04
# Delete's the default start.sh file from RunPod (so we can replace it with our own below)
270
+
# Delete's the default start.sh file from Runpod (so we can replace it with our own below)
271
271
RUN rm ../start.sh
272
272
273
273
# Copy all of our files into the container
@@ -284,7 +284,7 @@ RUN ls -la $WORKSPACE_DIR/start.sh
284
284
CMD $WORKSPACE_DIR/start.sh
285
285
```
286
286
Key features:
287
-
*`FROM runpod/pytorch:2.0.1-py3.10-cuda11.8.0-devel-ubuntu22.04`: Starts with a RunPod base image that comes with nginx, runpodctl, and other helpful base packages.
287
+
*`FROM runpod/pytorch:2.0.1-py3.10-cuda11.8.0-devel-ubuntu22.04`: Starts with a Runpod base image that comes with nginx, runpodctl, and other helpful base packages.
288
288
*`ARG WORKSPACE_DIR=/workspace` and `ENV WORKSPACE_DIR=${WORKSPACE_DIR}`: Allows the workspace directory to be set at build time.
289
289
*`WORKDIR $WORKSPACE_DIR`: Sets the working directory to the value of `WORKSPACE_DIR`.
0 commit comments