File: test_pool.py

package info (click to toggle)
python-pyepics 3.4.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,080 kB
  • sloc: python: 11,184; makefile: 106; javascript: 104; sh: 1
file content (51 lines) | stat: -rw-r--r-- 1,279 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import print_function
import sys
from contextlib import contextmanager
import epics
import multiprocessing as mp
import pytest

import pvnames
PVS = [pvnames.double_pv, pvnames.double_pv2]


@contextmanager
def pool_ctx():
    pool = epics.CAPool()
    yield pool
    pool.close()
    pool.join()


@pytest.mark.skipif(sys.version_info >= (3, 0),
                    reason='CAPool not functioning in Python 3')
def test_caget():
    with pool_ctx() as pool:
        print('Using caget() in subprocess pools:')
        print('\tpool.process =', pool.Process)
        values = pool.map(epics.caget, PVS)

        for pv, value in zip(PVS, values):
            print('\t%s = %s' % (pv, value))


def _manager_test_fcn(pv_dict, pv):
    pv_dict[pv] = epics.caget(pv)


@pytest.mark.skipif(sys.version_info >= (3, 0),
                    reason='CAPool not functioning in Python 3')
def test_manager():
    '''
    Fill up a shared dictionary using a manager
    '''
    with pool_ctx() as pool:
        print('Multiprocessing Manager test:')

        manager = mp.Manager()
        pv_dict = manager.dict()

        results = [pool.apply_async(_manager_test_fcn, [pv_dict, pv])
                   for pv in PVS]

    print('\tResulting pv dictionary: %s' % pv_dict)