Skip to content

37 alternative concurrency handling#38

Merged
Monarda merged 19 commits into
mainfrom
37-alternative-concurrency-handling
Sep 24, 2025
Merged

37 alternative concurrency handling#38
Monarda merged 19 commits into
mainfrom
37-alternative-concurrency-handling

Conversation

@Monarda

@Monarda Monarda commented Sep 21, 2025

Copy link
Copy Markdown
Contributor

This is a messy PR because it includes fixes for the problems in the previous PR merged into main. However, once those are excluded there are two places to look. Firstly, the file test/integrations/test_mixed_concurrency.py shows what these changes allow. It's not possible to use threading and asyncio in the same program.

Then the files in p4pillon/thread and p4pillon/asyncio use a version of monkey-patching to slightly alter the base files to use the appropriate concurrency model.

Many of the remaining changes are then switching from the p4pillon.concurrency string to the new method.

@Monarda Monarda linked an issue Sep 21, 2025 that may be closed by this pull request
@Monarda
Monarda requested a review from kurup September 21, 2025 21:12
@Monarda

Monarda commented Sep 21, 2025

Copy link
Copy Markdown
Contributor Author

This example may make it more obvious than the new tests what this allows:

from p4p.server import Server

from p4pillon.asyncio.sharednt import SharedNT as AsyncioSharedNT
from p4pillon.nt import NTScalar
from p4pillon.thread.sharednt import SharedNT as ThreadSharedNT

a = AsyncioSharedNT(nt=NTScalar("d"), initial=5.5)
b = ThreadSharedNT(nt=NTScalar("d"), initial=9.9)

Server.forever(
    providers=[
        {
            "demo:a": a,
            "demo:b": b,
        }
    ]
)

You'll need to do your own pvgets

@Monarda
Monarda marked this pull request as draft September 22, 2025 15:06
@Monarda

Monarda commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

A little more thought... I think I can see how to do some (all?) of this with straightforward subclassing rather than weird monkey-patching.

@Monarda

Monarda commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

The latest commit shows an example for server of using subclasses in a straightforward way to control the concurrency model.

I've also begun adding ABC to those classes that aren't intended to have concrete instances without specifying the concurrency model.

@Monarda

Monarda commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

These changes weren't as wide-ranging as I expected. And, in fact, even the change to server isn't fundamentally different to the monkey-patching route.

However, this does now include adding ABC (abstract base class) in a number of places. This means that, for example. only p4pillon.thread.server or p4pillon.asyncio.server may be instantiated. p4pillon.server.server can be used to specify an interface but it can't be itself instantiated any longer. I've even added this into p4p.server.raw.SharedPV so you can no longer accidentally use it.

@Monarda
Monarda marked this pull request as ready for review September 22, 2025 21:48
@Monarda
Monarda merged commit 1e1e8d5 into main Sep 24, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alternative concurrency handling

3 participants