interactive-sonification / sc3nb

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

ERROR: unable to receive /return message from sclang #22

Open avallintine opened 4 months ago

avallintine commented 4 months ago

Windows 10 Pro, Python 3.11.9, SuperCollider 3.13.0.

Also tested with Python 3.12 and SuperCollider 3.12.2 and 3.11.2 with same outcome.

Haven't had any problems using SuperCollider through the IDE.

Tried increasing timeout on line 459 to 20 seconds and disabling Windows Firewall, but no luck.

Please help :)

Output of IPython session:

Python 3.11.9 | packaged by Anaconda, Inc. | (main, Apr 19 2024, 16:40:41) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.25.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import sc3nb as scn

In [2]: sc = scn.startup()
<IPython.core.display.Javascript object>
[sclang | start reading ]
Starting sclang process... Done.
Registering OSC /return callback in sclang... Done.
Loading default sc3nb SynthDefs... Done.
[scsynth | start reading ]
Booting SuperCollider Server... Done.
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>
sc3>
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.
---------------------------------------------------------------------------
ProcessTimeout                            Traceback (most recent call last)
File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sclang.py:459, in SCLang.connect_to_server(self, server)
    458 try:  # if there are 'too many users' we failed. So the Exception is the successful case!
--> 459     self.read(expect="too many users", timeout=0.3, print_error=False)
    460 except ProcessTimeout:

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sclang.py:384, in SCLang.read(self, expect, timeout, print_error)
    383     print(error_str + timeout_error.output)
--> 384 raise timeout_error

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sclang.py:371, in SCLang.read(self, expect, timeout, print_error)
    370 try:
--> 371     return self.process.read(expect=expect, timeout=timeout)
    372 except ProcessTimeout as timeout_error:

File ~\Anaconda3\envs\sc3nb_foo\Lib\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:

ProcessTimeout: Reading of sclang timed out after 0.3s while expecting: "too many users"

During handling of the above exception, another exception occurred:

Empty                                     Traceback (most recent call last)
File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sclang.py:309, in SCLang.cmd(self, code, pyvars, verbose, discard_output, get_result, print_error, get_output, timeout)
    308 try:
--> 309     return_val = self._server.returns.get(timeout)
    310 except Empty as empty_exception:

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\osc\osc_communication.py:639, in MessageQueue.get(self, timeout, skip)
    638     self._skips -= 1
--> 639 val = self._queue.get(block=True, timeout=timeout)
    640 self._queue.task_done()

File ~\Anaconda3\envs\sc3nb_foo\Lib\queue.py:179, in Queue.get(self, block, timeout)
    178 if remaining <= 0.0:
--> 179     raise Empty
    180 self.not_empty.wait(remaining)

Empty:

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

SCLangError                               Traceback (most recent call last)
File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sc.py:280, in SC._try_to_connect(self)
    279 try:
--> 280     self._sclang.connect_to_server(self._server)
    281 except Exception as excep:

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sclang.py:462, in SCLang.connect_to_server(self, server)
    461 self._server = server
--> 462 self._port = self.cmdg("NetAddr.langPort", verbose=False)
    463 _LOGGER.info("Connecting %s with %s", self._server, self)

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sclang.py:344, in SCLang.cmdg(self, code, **kwargs)
    343     kwargs["pyvars"] = parse_pyvars(code)
--> 344 return self.cmd(code, get_result=True, **kwargs)

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sclang.py:316, in SCLang.cmd(self, code, pyvars, verbose, discard_output, get_result, print_error, get_output, timeout)
    315             print(out)
--> 316         raise SCLangError(
    317             "unable to receive /return message from sclang", sclang_output=out
    318         ) from empty_exception
    319 out = self.read(expect=self._repl_return, timeout=timeout)

SCLangError: unable to receive /return message from sclang

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

RuntimeError                              Traceback (most recent call last)
Cell In[2], line 1
----> 1 sc = scn.startup()

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sc.py:67, in startup(start_server, scsynth_path, start_sclang, sclang_path, magic, scsynth_options, with_blip, console_logging, allowed_parents, timeout)
     64         magics.load_ipython_extension(ipy)
     66 if SC.default is None:
---> 67     SC.default = SC(
     68         start_server=start_server,
     69         scsynth_path=scsynth_path,
     70         start_sclang=start_sclang,
     71         sclang_path=sclang_path,
     72         scsynth_options=scsynth_options,
     73         with_blip=with_blip,
     74         console_logging=console_logging,
     75         allowed_parents=allowed_parents,
     76         timeout=timeout,
     77     )
     78 else:
     79     _LOGGER.warning("SC already started")

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sc.py:177, in SC.__init__(self, start_server, scsynth_path, start_sclang, sclang_path, scsynth_options, with_blip, console_logging, allowed_parents, timeout)
    170         self.start_sclang(
    171             sclang_path=sclang_path,
    172             console_logging=self._console_logging,
    173             allowed_parents=allowed_parents,
    174             timeout=timeout,
    175         )
    176     if start_server:
--> 177         self.start_server(
    178             scsynth_path=scsynth_path,
    179             scsynth_options=scsynth_options,
    180             console_logging=self._console_logging,
    181             with_blip=with_blip,
    182             allowed_parents=allowed_parents,
    183             timeout=timeout,
    184         )
    185 except Exception:
    186     if SC.default is self:

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sc.py:271, in SC.start_server(self, scsynth_options, scsynth_path, console_logging, with_blip, allowed_parents, timeout)
    269         raise RuntimeError(f"Starting scsynth failed - {excep}") from excep
    270     else:
--> 271         self._try_to_connect()
    272 else:
    273     _LOGGER.warning("scsynth already started")

File ~\Anaconda3\envs\sc3nb_foo\Lib\site-packages\sc3nb\sc.py:282, in SC._try_to_connect(self)
    280     self._sclang.connect_to_server(self._server)
    281 except Exception as excep:
--> 282     raise RuntimeError(
    283         f"connecting {self._sclang} to {self._server} failed"
    284     ) from excep

RuntimeError: connecting <SCLang process=<Process 'sclang' (running) pid=1788>> to <SCServer addr=('127.0.0.1', 57110), process=<Process 'scsynth' (running) pid=14840>> failed
avallintine commented 4 months ago

Tried increasing timeout on line 459 to 20 seconds and disabling Windows Firewall, but no luck.

Also tried increasing global timeout:

scn.startup(timeout=20)

But it still times out when waiting for a response from sclang.

Not sure if this helps identify the problem, but while running the same code in VS Code I am getting a different error:

Starting sclang process... [sclang | start reading ]
Done.
Registering OSC /return callback in sclang... Timeout while reading sclang
expected: "->" (sclang return value)
output until timeout below: (also see console)
----------------------------------------------
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; };
sc3nb - Registering OSC /return callback
-> ( 'callback': a Function )
sc3>

Traceback (most recent call last):
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sc.py", line 214, in start_sclang
    self._sclang.start(
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sclang.py", line 121, in start
    self.init()
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sclang.py", line 131, in init
    self.cmds(
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sclang.py", line 338, in cmds
    return self.cmd(code, verbose=False, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sclang.py", line 319, in cmd
    out = self.read(expect=self._repl_return, timeout=timeout)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sclang.py", line 384, in read
    raise timeout_error
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sclang.py", line 371, in read
    return self.process.read(expect=expect, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\process_handling.py", line 247, in read
    raise ProcessTimeout(
sc3nb.process_handling.ProcessTimeout: Reading of sclang timed out after 1s while expecting: "->"

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

Traceback (most recent call last):
  File "D:\projects\supercollider_foo\sc3nb_foo.py", line 3, in <module>
    sc = scn.startup(timeout=20)
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sc.py", line 67, in startup
    SC.default = SC(
                 ^^^
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sc.py", line 170, in __init__
    self.start_sclang(
  File "c:\Users\avallintine\Anaconda3\envs\supercollider_foo\Lib\site-packages\sc3nb\sc.py", line 222, in start_sclang
    raise RuntimeError(f"Starting sclang failed - {excep}") from excep
RuntimeError: Starting sclang failed - Reading of sclang timed out after 1s while expecting: "->"
[sclang | reached EOF ]
Exiting sclang... Done.
dreinsch commented 4 months ago

Sorry for the late reply. I hope this still helps! This seems to be the following issue - https://github.com/interactive-sonification/sc3nb/issues/18 Please install and try using the development version by using pip install git+https://github.com/interactive-sonification/sc3nb.git@develop

avallintine commented 4 months ago

That worked. Thanks!

LFSaw commented 3 months ago

this also fixes it on OSX, apparently. Thanks!