Esempio n. 1
0
def test_manager():
    #~ logger.level = logging.DEBUG
    mgr = create_manager('rpc', auto_close_at_exit=False)

    #~ print(type(mgr))
    #~ exit()
    # Create a local Host to communicate with
    host_proc, host = Host.spawn('test-host')
    host_addr = host_proc.client.address

    # test connection to host
    host = mgr.get_host(host_addr)
    assert mgr.list_hosts() == [host]

    # create nodegroup
    assert mgr.list_nodegroups() == []
    ng1 = mgr.create_nodegroup('nodegroup1', host)
    assert mgr.list_nodegroups() == [ng1]

    assert ng1.list_nodes() == []
    n1 = ng1.create_node('_MyTestNode')
    assert ng1.list_nodes() == [n1]
    n1.initialize()
    n1.configure()
    n1.start()
    n1.stop()
    ng1.remove_node(n1)
    assert ng1.list_nodes() == []

    # Need to close manager here because otherwise atexit hooks will kill the
    # host, which results in the manager complaining that it was unable to
    # kill the nodegroup. In real situations, we do not expect the host to
    # disappear before the manager does.
    mgr.close()
Esempio n. 2
0
def test_manager():
    #~ logger.level = logging.DEBUG
    mgr = create_manager('rpc', auto_close_at_exit=False)
    
    #~ print(type(mgr))
    #~ exit()
    # Create a local Host to communicate with
    host_proc, host = Host.spawn('test-host')
    host_addr = host_proc.client.address
    
    # test connection to host
    host = mgr.get_host(host_addr)
    assert mgr.list_hosts() == [host]
    
    # create nodegroup 
    assert mgr.list_nodegroups() == []
    ng1 = mgr.create_nodegroup('nodegroup1', host)
    assert mgr.list_nodegroups() == [ng1]
    

    assert ng1.list_nodes() == []
    n1 = ng1.create_node('_MyTestNode')
    assert ng1.list_nodes() == [n1]
    n1.initialize()
    n1.configure()
    n1.start()
    n1.stop()
    ng1.remove_node(n1)
    assert ng1.list_nodes() == []

    # Need to close manager here because otherwise atexit hooks will kill the
    # host, which results in the manager complaining that it was unable to
    # kill the nodegroup. In real situations, we do not expect the host to
    # disappear before the manager does. 
    mgr.close()
Esempio n. 3
0
def test_close_manager_implicit():
    man = create_manager(auto_close_at_exit=True)
    nodegroups = create_some_node_group(man)

    for ng in nodegroups:
        ng.start_all_nodes()
    time.sleep(1.0)
    for ng in nodegroups:
        ng.stop_all_nodes()

    time.sleep(2.0)
Esempio n. 4
0
def test_close_manager_explicit():
    #logging.getLogger().level = logging.DEBUG
    man = create_manager(auto_close_at_exit=False)
    nodegroups = create_some_node_group(man)

    for ng in nodegroups:
        ng.start_all_nodes()
    time.sleep(1.)
    for ng in nodegroups:
        ng.stop_all_nodes()

    man.close()
Esempio n. 5
0
def test_close_manager_explicit():
    #logging.getLogger().level = logging.DEBUG
    man = create_manager(auto_close_at_exit=False)
    nodegroups = create_some_node_group(man)
    
    for ng in nodegroups:
        ng.start_all_nodes()
    time.sleep(1.)
    for ng in nodegroups:
        ng.stop_all_nodes()
    
    man.close()
Esempio n. 6
0
Custom RPC client

Demonstrate the most simple use of zmq and json to create a client that
connects to an RPCServer. This provides a basic template for connecting
to pyacq from non-Python platforms.

One important note before we start: pyacq's remote API is not actually different
from its internal Python API. Any function you can call from within Python
can also be invoked remotely by RPC calls. The example below deals entirely
with pyacq's RPC protocol--how translate between the Python API and the raw
packets handled by zeroMQ.
"""

# First we will start a manager in a subprocess to test our client against
from pyacq.core import create_manager
manager = create_manager('rpc')
address = manager._rpc_addr

# --- From here on, we don't use any pyacq code ---
import json, zmq


# Here's how we connect to a new server (we will likely want to connect to
# multiple servers)
def create_socket(address, name):
    """Return a ZeroMQ socket connected to an RPC server.
    
    Parameters
    ----------
    address : str
        The zmq interface where the server is listening (e.g.
Esempio n. 7
0
Streams audio data to a QTimeFreq Node, which displays a frequency spectrogram
from a Morlet continuous wavelet transform.
"""

from pyacq.devices.audio_pyaudio import PyAudio
from pyacq.viewers import QTimeFreq
from pyacq.core import create_manager
import pyqtgraph as pg


# Start Qt application
app = pg.mkQApp()


# Create a manager to spawn worker process to record and process audio
man = create_manager()
ng = man.create_nodegroup()


# Create PyAudio device node in remote process
dev = ng.create_node('PyAudio')

# Configure PyAudio device with a single (default) input channel.
default_input = dev.default_input_device()
dev.configure(nb_channel=1, sample_rate=44100., input_device_index=default_input,
              format='int16', chunksize=1024)
dev.output.configure(protocol='tcp', interface='127.0.0.1', transfermode='plaindata')
dev.initialize()


# We are only recording a single audio channel, so we create one extra 
Esempio n. 8
0
Simple demonstration of streaming data from a PyAudio device to a QOscilloscope
viewer.

Both device and viewer nodes are created locally without a manager.
"""

from pyacq.devices.audio_pyaudio import PyAudio
from pyacq.viewers import QTimeFreq
from pyacq.core import create_manager
import pyqtgraph as pg

# Start Qt application
app = pg.mkQApp()

# Create a manager to spawn worker process to record and process audio
man = create_manager()
ng = man.create_nodegroup()

# Create PyAudio device node in remote process
dev = ng.create_node('PyAudio')

# Configure PyAudio device with a single (default) input channel.
default_input = dev.default_input_device()
dev.configure(nb_channel=1,
              sample_rate=44100.,
              input_device_index=default_input,
              format='int16',
              chunksize=1024)
dev.output.configure(protocol='tcp',
                     interface='127.0.0.1',
                     transfertmode='plaindata')
Esempio n. 9
0
Custom RPC client

Demonstrate the most simple use of zmq and json to create a client that
connects to an RPCServer. This provides a basic template for connecting
to pyacq from non-Python platforms.

One important note before we start: pyacq's remote API is not actually different
from its internal Python API. Any function you can call from within Python
can also be invoked remotely by RPC calls. The example below deals entirely
with pyacq's RPC protocol--how translate between the Python API and the raw
packets handled by zeroMQ.
"""

# First we will start a manager in a subprocess to test our client against
from pyacq.core import create_manager
manager = create_manager('rpc')
address = manager._rpc_addr


# --- From here on, we don't use any pyacq code ---
import json, zmq

# Here's how we connect to a new server (we will likely want to connect to
# multiple servers)
def create_socket(address, name):
    """Return a ZeroMQ socket connected to an RPC server.
    
    Parameters
    ----------
    address : str
        The zmq interface where the server is listening (e.g.