Skip to content

Commit c257a0c

Browse files
committed
Add option for passing an alternative cothread callback dispatcher
This adds an extra optional argument to CothreadDispatcher. The only realistically sensible alternative argument is probably cothread.Spawn.
1 parent d06e9f7 commit c257a0c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

softioc/cothread_dispatcher.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11

22
class CothreadDispatcher:
3-
def __init__(self):
3+
def __init__(self, dispatcher = None):
44
"""A dispatcher for `cothread` based IOCs, suitable to be passed to
5-
`softioc.iocInit`. """
6-
# Import here to ensure we don't instantiate any of cothread's global
7-
# state unless we have to
8-
import cothread
9-
# Create our own cothread callback queue so that our callbacks
10-
# processing doesn't interfere with other callback processing.
11-
self.__dispatcher = cothread.cothread._Callback()
5+
`softioc.iocInit`. By default scheduled tasks are run on a dedicated
6+
cothread callback thread, but an alternative dispatcher can optionally
7+
be specified here. Realistically the only sensible alternative is to
8+
pass `cothread.Spawn`, which would create a separate cothread for each
9+
dispatched callback.
10+
"""
11+
12+
if dispatcher is None:
13+
# Import here to ensure we don't instantiate any of cothread's
14+
# global state unless we have to
15+
import cothread
16+
# Create our own cothread callback queue so that our callbacks
17+
# processing doesn't interfere with other callback processing.
18+
self.__dispatcher = cothread.cothread._Callback()
19+
else:
20+
self.__dispatcher = dispatcher
1221

1322
def __call__(
1423
self,

0 commit comments

Comments
 (0)