interactive-sonification / sc3nb

sc3nb - SuperCollider3 interface for python and jupyter notebooks
MIT License
32 stars 8 forks source link

Crash at startup with Python 3.11 #18

Closed AntiAura closed 11 months ago

AntiAura commented 1 year ago

Hello,

I'm on Manjaro using the supercollider package from the official repository and installed sc3nb over pip inside an anaconda (python 3.11.0) environment. When I run a simple

import sc3nb as scn
sc = scn.startup()

it crashes with the following error message (from jupyter notebook):

Starting sclang process... [sclang | start reading ]
[sclang]  compiling class library...
[sclang]    Found 867 primitives.
[sclang]    Compiling directory '/usr/share/SuperCollider/SCClassLibrary'
[sclang]    Compiling directory '/usr/share/SuperCollider/Extensions'
[sclang]    Compiling directory '/home/sentinel/.local/share/SuperCollider/Extensions'
[sclang]    numentries = 1279205 / 19274352 = 0.066
[sclang]    5716 method selectors, 3372 classes
[sclang]    method table size 20669904 bytes, big table size 154194816
[sclang]    Number of Symbols 14876
[sclang]    Byte Code Size 437565
[sclang]    compiled 553 files in 0.93 seconds
[sclang]  
[sclang]  Info: 4 methods are currently overwritten by extensions. To see which, execute:
[sclang]  MethodOverride.printAll
[sclang]  
[sclang]  compile done
[sclang]  localhost : setting clientID to 0.
[sclang]  internal : setting clientID to 0.
[sclang]  Class tree inited in 0.01 seconds
[sclang]  
[sclang]  
[sclang]  *** Welcome to SuperCollider 3.12.2. *** For help type ctrl-c ctrl-h (Emacs) or :SChelp (vim) or ctrl-U (sced/gedit).
Done.
Registering OSC /return callback in sclang... [sclang]  sc3> "sc3nb - Registering OSC /return callback".postln; r = r ? (); r.callback = { arg code, ip, port; var result = code.interpret; var addr = NetAddr.new(ip, port); var prependSize = { arg elem; if (elem.class == Array){ elem = [elem.size] ++ elem.collect(prependSize); }{ elem; }; }; var msgContent = prependSize.value(result); addr.sendMsg("ReplyAddress.RETURN_ADDR", msgContent); result; };
...
-> 57120
sc3> Requested notification messages from server 'sc3nb_remote'
sc3nb_remote: server process has maxLogins 8 - adjusting my options accordingly.
sc3nb_remote: keeping clientID (0) as confirmed by server process.
Output exceeds the [size limit](command:workbench.action.openSettings?[). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?76a7e08d-8f21-4273-bae1-902c30461c66)
---------------------------------------------------------------------------
ProcessTimeout                            Traceback (most recent call last)
File ~/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py:458, in SCLang.connect_to_server(self, server)
    457 try:  # if there are 'too many users' we failed. So the Exception is the successful case!
--> 458     self.read(expect="too many users", timeout=0.3, print_error=False)
    459 except ProcessTimeout:

File ~/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py:383, in SCLang.read(self, expect, timeout, print_error)
    382     print(error_str + timeout_error.output)
--> 383 raise timeout_error

File ~/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py:370, in SCLang.read(self, expect, timeout, print_error)
    369 try:
--> 370     return self.process.read(expect=expect, timeout=timeout)
    371 except ProcessTimeout as timeout_error:

File ~/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/process_handling.py:247, in Process.read(self, expect, timeout)
    246 if time.time() >= timeout_time:
--> 247     raise ProcessTimeout(
    248         executable=self.executable,
    249         timeout=timeout,
    250         output=out,
    251         expected=expect,
    252     )
    253 try:
...
--> 282     raise RuntimeError(
    283         f"connecting {self._sclang} to {self._server} failed"
    284     ) from excep

RuntimeError: connecting <SCLang process=<Process 'sclang' (running) pid=9437>> to <SCServer addr=('127.0.0.1', 57110), process=<Process 'scsynth' (running) pid=9482>> failed
dreinsch commented 1 year ago

Hi,

Thank you for the report.

It seems like the output is clipped. Can you provide the full output? There should be some line starting with [scsynth] or [scsynth | start reading ]?

It is possible that sc3nb is unable to find the scsynth executable. Is it in $PATH ? / Can you start the server in the commandline using scsynth?

What happens if you start without sclang by using: scn.startup(start_sclang=False)?

Sometimes increasing the timeout also helps. You could try scn.startup(timeout=20)

AntiAura commented 1 year ago

Here is the full output from python interactive:

> conda activate sound_synth
> python
Python 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:27:40) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sc3nb as scb
>>> scb.startup()
[sclang | start reading ]
[sclang]  compiling class library...
[sclang]    Found 867 primitives.
[sclang]    Compiling directory '/usr/share/SuperCollider/SCClassLibrary'
[sclang]    Compiling directory '/usr/share/SuperCollider/Extensions'
[sclang]    Compiling directory '/home/sentinel/.local/share/SuperCollider/Extensions'
[sclang]    numentries = 1279205 / 19274352 = 0.066
[sclang]    5716 method selectors, 3372 classes
[sclang]    method table size 20669904 bytes, big table size 154194816
[sclang]    Number of Symbols 14876
[sclang]    Byte Code Size 437565
[sclang]    compiled 553 files in 0.78 seconds
[sclang]  
[sclang]  Info: 4 methods are currently overwritten by extensions. To see which, execute:
[sclang]  MethodOverride.printAll
[sclang]  
[sclang]  compile done
[sclang]  localhost : setting clientID to 0.
[sclang]  internal : setting clientID to 0.
[sclang]  Class tree inited in 0.01 seconds
[sclang]  
[sclang]  
[sclang]  *** Welcome to SuperCollider 3.12.2. *** For help type ctrl-c ctrl-h (Emacs) or :SChelp (vim) or ctrl-U (sced/gedit).
Starting sclang process... Done.
[sclang]  sc3> "sc3nb - Registering OSC /return callback".postln; r = r ? (); r.callback = { arg code, ip, port; var result = code.interpret; var addr = NetAddr.new(ip, port); var prependSize = { arg elem; if (elem.class == Array){ elem = [elem.size] ++ elem.collect(prependSize); }{ elem; }; }; var msgContent = prependSize.value(result); addr.sendMsg("ReplyAddress.RETURN_ADDR", msgContent); result; };
[sclang]  sc3nb - Registering OSC /return callback
[sclang]  -> ( 'callback': a Function )
Registering OSC /return callback in sclang... Done.
[sclang]  sc3> "sc3nb - Loading SynthDefs from ^synthdef_path".postln; PathName.new("/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/resources/synthdefs").files.collect( { |path| (path.extension == "scsyndef").if({SynthDescLib.global.read(path); path;})} );
[sclang]  sc3nb - Loading SynthDefs from ^synthdef_path
[sclang]  -> [ nil, PathName(/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/resources/synthdefs/pb-1ch.scsyndef), PathName(/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/resources/synthdefs/pb-2ch.scsyndef), PathName(/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/resources/synthdefs/record-1ch.scsyndef), PathName(/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/resources/synthdefs/record-2ch.scsyndef), P...etc...
Loading default sc3nb SynthDefs... Done.
[scsynth | start reading ]
[scsynth]  Faust: supercollider.cpp: sc_api_version = 3
[scsynth]  Faust: FaustGreyholeRaw numControls=7
[scsynth]  Faust: supercollider.cpp: sc_api_version = 3
[scsynth]  Faust: FaustJPverbRaw numControls=11
[scsynth]  Found 118 LADSPA plugins
[scsynth]  JackDriver: client name is 'SuperCollider'
[scsynth]  SC_AudioDriver: sample rate = 48000.000000, driver's block size = 1024
[scsynth]  SuperCollider 3 server ready.
Booting SuperCollider Server... Done.
[sclang]  sc3> "sc3nb - Connecting sclang to scsynth".postln; Server.default=s=Server.remote('sc3nb_remote', NetAddr("127.0.0.1",57110), options:ServerOptions.new, clientID:0);
[sclang]  sc3nb - Connecting sclang to scsynth
[sclang]  sc3nb_remote : setting clientID to 0.
[sclang]  -> Server
[sclang]  sc3> r['callback'].value("NetAddr.langPort", "127.0.0.1", 57131);
[sclang]  -> 57120
[sclang]  sc3> Requested notification messages from server 'sc3nb_remote'
[sclang]  sc3nb_remote: server process has maxLogins 8 - adjusting my options accordingly.
[sclang]  sc3nb_remote: keeping clientID (0) as confirmed by server process.
ERROR: unable to receive /return message from sclang
sclang output: (also see console) 

sc3> r['callback'].value("NetAddr.langPort", "127.0.0.1", 57131);
-> 57120
sc3> Requested notification messages from server 'sc3nb_remote'
sc3nb_remote: server process has maxLogins 8 - adjusting my options accordingly.
sc3nb_remote: keeping clientID (0) as confirmed by server process.
Traceback (most recent call last):
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py", line 458, in connect_to_server
    self.read(expect="too many users", timeout=0.3, print_error=False)
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py", line 383, in read
    raise timeout_error
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py", line 370, in read
    return self.process.read(expect=expect, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/process_handling.py", line 247, in read
    raise ProcessTimeout(
sc3nb.process_handling.ProcessTimeout: Reading of sclang timed out after 0.3s while expecting: "too many users"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py", line 308, in cmd
    return_val = self._server.returns.get(timeout)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/osc/osc_communication.py", line 570, in get
    val = self._queue.get(block=True, timeout=timeout)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/queue.py", line 179, in get
    raise Empty
_queue.Empty

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sc.py", line 280, in _try_to_connect
    self._sclang.connect_to_server(self._server)
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py", line 461, in connect_to_server
    self._port = self.cmdg("NetAddr.langPort", verbose=False)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py", line 343, in cmdg
    return self.cmd(code, get_result=True, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sclang.py", line 315, in cmd
    raise SCLangError(
sc3nb.sclang.SCLangError: unable to receive /return message from sclang

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sc.py", line 67, in startup
    SC.default = SC(
                 ^^^
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sc.py", line 177, in __init__
    self.start_server(
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sc.py", line 271, in start_server
    self._try_to_connect()
  File "/home/sentinel/anaconda3/envs/sound_synth/lib/python3.11/site-packages/sc3nb/sc.py", line 282, in _try_to_connect
    raise RuntimeError(
RuntimeError: connecting <SCLang process=<Process 'sclang' (running) pid=55058>> to <SCServer addr=('127.0.0.1', 57110), process=<Process 'scsynth' (running) pid=55114>> failed
>>> 

Also, scynth can be executed from cmd:

> which scsynth
/usr/bin/scsynth
dreinsch commented 1 year ago

Sorry for the late reply. I finally managed to reproduce this issue after receiving a similar report. The problem seems to be related with Python 3.11

Can you please try the following work around and report back if it also works for you?

sc = scn.startup(start_server=False)
sc.lang.cmds(
    r"""
        "sc3nb - Registering OSC /return callback".postln;
        // NetAddr.useDoubles = true;
        r = r ? ();
        r.callback = { arg code, ip, port;
            var result = code.interpret;
            var addr = NetAddr.new(ip, port);
            var prependSize = { arg elem;
                if (elem.class == Array){
                    elem = [elem.size] ++ elem.collect(prependSize);
                }{
                    elem;
                };
            };
            var msgContent = prependSize.value(result);
            addr.sendMsg(^replyAddress, msgContent);
            result;  // result should be returned
        };""",
    pyvars={"replyAddress": "/return"},
)
sc.start_server()
AntiAura commented 1 year ago

Yes, it seems to be working with these additional settings. Thank you!

dreinsch commented 11 months ago

The issue was caused by https://github.com/python/cpython/issues/100458 and is now fixed.