Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantee scsynth exits when Python exits #342

Merged
merged 4 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,19 @@ jobs:
Scream\Install\helpers\devcon-x64.exe install Scream\Install\driver\x64\Scream.inf *Scream
net start audiosrv
Get-CimInstance Win32_SoundDevice | fl *
timeout-minutes: 2
- name: Sanity-check Supriya
run: |
python -c "import logging, supriya; logging.getLogger('supriya').setLevel(logging.INFO); logging.basicConfig(); server = supriya.Server().boot(); server.quit(); exit()"
python -c "import logging, supriya; logging.getLogger('supriya').setLevel(logging.INFO); logging.basicConfig(); server = supriya.Server().boot(); exit()"
python -c "from supriya.utils._intervals import IntervalTreeDriverEx; print(IntervalTreeDriverEx)"
- name: Sanity-check Supriya SHM (Non-Windows)
if: ${{ matrix.os != 'windows-latest' }}
run: python -c "from supriya.contexts.shm import ServerSHM; print(ServerSHM)"
- name: Check for stray processes (Non-Windows)
if: ${{ matrix.os != 'windows-latest' }}
run: |
! ( ps aux | grep scsynth | grep -v grep )
! ( ps aux | grep supernova | grep -v grep )
- name: Install Supriya test dependencies
run: pip install -e .[test]
- name: Install ffmpeg
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ classifiers = [
"Topic :: Multimedia :: Sound/Audio :: Sound Synthesis",
]
dependencies = [
"PyYAML >= 6.0",
"platformdirs >= 3.1.0",
"platformdirs >= 3.9.1",
"uqbar >= 0.6.9",
]
description = "A Python API for SuperCollider"
Expand Down Expand Up @@ -100,7 +99,7 @@ exclude_lines = [

[tool.isort]
case_sensitive = true
known_third_party = ["uqbar", "yaml"]
known_third_party = ["uqbar"]
profile = "black"
skip = "supriya/__init__.py"

Expand Down
2 changes: 1 addition & 1 deletion supriya/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

This follows black's versioning scheme.
"""
__version_info__ = (23, "6b0")
__version_info__ = (23, "7b0")
__version__ = ".".join(str(x) for x in __version_info__)
6 changes: 6 additions & 0 deletions supriya/scsynth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import atexit
import enum
import logging
import os
Expand Down Expand Up @@ -280,6 +281,10 @@ def _handle_line(self, line):


class SyncProcessProtocol(ProcessProtocol):
def __init__(self):
super().__init__()
atexit.register(self.quit)

def boot(self, options: Options):
if self.is_running:
return
Expand All @@ -289,6 +294,7 @@ def boot(self, options: Options):
list(options),
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
start_new_session=True,
)
start_time = time.time()
timeout = 10
Expand Down
27 changes: 14 additions & 13 deletions supriya/synthdefs/synthdefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import tempfile
from typing import Dict, List, Optional, Sequence, Tuple, Union

import yaml

from .. import sclang
from ..enums import (
BinaryOperator,
Expand Down Expand Up @@ -248,17 +246,20 @@ def get_parameter_name(input_, output_index=0):
)
ugen_dict[argument_name] = value
ugens.append({ugen_name: ugen_dict or None})

result = {
"synthdef": {
"name": self.actual_name,
# 'hash': self.anonymous_name,
"ugens": ugens,
}
}
return yaml.dump(
result, default_flow_style=False, indent=4, sort_keys=False
).rstrip()
result = [
"synthdef:",
f" name: {self.actual_name}",
" ugens:",
]
for ugen in ugens:
for ugen_name, ugen_dict in ugen.items():
if not ugen_dict:
result.append(f" - {ugen_name}: null")
continue
result.append(f" - {ugen_name}:")
for parameter_name, parameter_value in ugen_dict.items():
result.append(f" {parameter_name}: {parameter_value}")
return "\n".join(result)

### PRIVATE METHODS ###

Expand Down