Skip to content

Commit 8f7b985

Browse files
authored
Merge pull request #300 from vkottler/dev/5.10.0
5.10.0 - Peer process management improvements
2 parents 92fbfab + ad78276 commit 8f7b985

File tree

11 files changed

+44
-23
lines changed

11 files changed

+44
-23
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
7878
- run: |
7979
mk python-release owner=vkottler \
80-
repo=runtimepy version=5.9.2
80+
repo=runtimepy version=5.10.0
8181
if: |
8282
matrix.python-version == '3.12'
8383
&& matrix.system == 'ubuntu-latest'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
=====================================
33
generator=datazen
44
version=3.1.4
5-
hash=663b9a39a640cae079d35c0621ae20f9
5+
hash=cbacac02049e2f568e5ebad3cc428033
66
=====================================
77
-->
88

9-
# runtimepy ([5.9.2](https://pypi.org/project/runtimepy/))
9+
# runtimepy ([5.10.0](https://pypi.org/project/runtimepy/))
1010

1111
[![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/)
1212
![Build Status](https://github.com/vkottler/runtimepy/workflows/Python%20Package/badge.svg)

local/variables/package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
major: 5
3-
minor: 9
4-
patch: 2
3+
minor: 10
4+
patch: 0
55
entry: runtimepy

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"
44

55
[project]
66
name = "runtimepy"
7-
version = "5.9.2"
7+
version = "5.10.0"
88
description = "A framework for implementing Python services."
99
readme = "README.md"
1010
requires-python = ">=3.12"

runtimepy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# =====================================
22
# generator=datazen
33
# version=3.1.4
4-
# hash=ba2f544d63fad56dd7605cf937fe52d8
4+
# hash=a9a53fbeb974140d3611fecadbce5da4
55
# =====================================
66

77
"""
@@ -10,7 +10,7 @@
1010

1111
DESCRIPTION = "A framework for implementing Python services."
1212
PKG_NAME = "runtimepy"
13-
VERSION = "5.9.2"
13+
VERSION = "5.10.0"
1414

1515
# runtimepy-specific content.
1616
METRICS_NAME = "metrics"

runtimepy/data/dummy_load.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ processes:
9898
9999
# The peer itself runs an arbiter process.
100100
config:
101+
config: *cfg
101102
includes:
102103
- package://runtimepy/server.yaml
103-
104104
app: runtimepy.sample.program.run
105-
config: *cfg
106105

107106
program: runtimepy.sample.program.SampleProgram

runtimepy/data/factories.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ factories:
4545

4646
# Useful subprocess peer interfaces.
4747
- {name: runtimepy.sample.peer.SamplePeer}
48+
- {name: runtimepy.subprocess.peer.RuntimepyPeer}
4849

4950
ports:
5051
# Reserve ports for JSON listeners.

runtimepy/data/schemas/PeerProcessConfig.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ includes:
55
- has_config.yaml
66
- has_markdown.yaml
77

8-
required: [program]
9-
108
properties:
119
program:
1210
type: string
11+
default: runtimepy.subprocess.program.PeerProgram

runtimepy/message/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# built-in
66
from io import BytesIO as _BytesIO
7-
from json import dumps, loads
7+
from json import JSONEncoder, dumps, loads
88
from typing import Any
99
from typing import Iterator as _Iterator
1010

@@ -18,6 +18,18 @@
1818
JsonMessage = dict[str, Any]
1919

2020

21+
class StrFallbackJSONEncoder(JSONEncoder):
22+
"""Custom JSON encoder."""
23+
24+
def default(self, o):
25+
"""Use a string conversion if necessary."""
26+
27+
try:
28+
return super().default(o)
29+
except TypeError:
30+
return str(o)
31+
32+
2133
class MessageProcessor:
2234
"""A class for parsing size-delimited messages."""
2335

@@ -48,7 +60,11 @@ def encode(self, stream: _BytesIO, data: bytes | str) -> None:
4860

4961
def encode_json(self, stream: _BytesIO, data: JsonMessage) -> None:
5062
"""Encode a message as JSON."""
51-
self.encode(stream, dumps(data, separators=(",", ":")))
63+
64+
self.encode(
65+
stream,
66+
dumps(data, cls=StrFallbackJSONEncoder, separators=(",", ":")),
67+
)
5268

5369
def messages(self, data: bytes) -> _Iterator[JsonMessage]:
5470
"""Iterate over incoming messages."""

runtimepy/sample/program.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
from vcorelib.math import RateLimiter
1010

1111
# internal
12-
from runtimepy.net.arbiter.info import AppInfo
12+
from runtimepy.net.arbiter.info import AppInfo, SampleStruct
1313
from runtimepy.subprocess.program import PeerProgram
1414

1515

1616
class SampleProgram(PeerProgram):
1717
"""A sample peer program."""
1818

19+
struct_type = SampleStruct
20+
1921
stderr_task: asyncio.Task[None]
2022

2123
async def log_message_sender(
@@ -91,4 +93,6 @@ async def run(app: AppInfo) -> int:
9193

9294
await prog.wait_json({"a": 1, "b": 2, "c": 3})
9395

96+
await app.stop.wait()
97+
9498
return 0

0 commit comments

Comments
 (0)