Replies: 3 comments 3 replies
|
Hello, I have continued my testing and I would like to propose the addition of a new feature for softioc. The idea is to have a function that is the opposite of interactive_ioc. A function that we could use with systemd. I have named it no_interactive_ioc. I tested it with Python 3 and it seems to work correctly. What do you think? def interactive_ioc(context = {}, call_exit = True):
'''Fires up the interactive IOC prompt with the given context.
Args:
context: A dictionary of values that will be made available to the
interactive Python shell together with a number of EPICS test
functions
call_exit: If `True`, the IOC will be terminated by calling epicsExit
which means that `interactive_ioc` will not return
'''
# Add all our commands to the given context.
exports = dict((key, globals()[key]) for key in command_names)
import code
try:
code.interact(local = dict(exports, **context), exitmsg = '')
except SystemExit as e:
if call_exit:
safeEpicsExit(e.code)
raise
if call_exit:
safeEpicsExit(0)
def no_interactive_ioc():
'''Starts the IOC without an interactive shell.'''
def on_exit():
imports.epicsExit(0)
for sig in ('SIGINT', 'SIGTERM'):
device.dispatcher.loop.add_signal_handler(getattr(signal, sig), on_exit)
import time
while not device.dispatcher.loop.is_closed():
time.sleep(0.1) |
1 reply
|
Hello @AlexanderWells-diamond , Thanks for your comment. I had forgotten that def not_interactive_ioc():
'''Launches IOC in non-interactive mode for background use'''
if device.dispatcher:
if hasattr(device.dispatcher, 'loop'):
# If loop present in device.dispatcher then use asyncrio
import asyncio
import threading
import signal
loop = device.dispatcher.loop
stop_event = threading.Event()
async def stop_loop():
imports.epicsExit(0)
stop_event.set() # Signal end of loop
def signal_exit():
asyncio.run_coroutine_threadsafe(stop_loop(), loop)
# Configure signal handlers to call signal_exit
for sig in ('SIGINT', 'SIGTERM'):
loop.add_signal_handler(getattr(signal, sig), signal_exit)
# Wait for end of loop
stop_event.wait()
else:
# If loop is not present in device.dispatcher then cotherd is used
import cothread
cothread.WaitForQuit()
imports.epicsExit(0)
else:
print("No dispatcher found") |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello everyone,
I managed to get softioc running without using
procServthrough systemd.Here's my example code:
And the associated service file:
To correctly have the information in systemd, you need to use the
-uoption of python or have the environment variablePYTHONUNBUFFERED=TRUE.Here's what it looks like with systemd:
All reactions