prattom
prattom

Reputation: 1743

Generating signals at a particular time in Python

I am running my code in Linux os. I want to know if it is possible to generate a signal at a particular time in one function which is caught by another function in Python code? By signal I mean like SIGALRM

Upvotes: 0

Views: 248

Answers (1)

A SIGALRM signal (read carefully signal(7) and time(7) ...) can be emitted by alarms or timers, notably those created by timer_create(2) and set by timer_settime(2) (or the older setitimer(2) ...). You set the signal handler using sigaction(2).

Notice that signals are sent to the process (or to some thread in it), independently of the function currently executed. They could be masked using sigprocmask(2).

If you want to send or raise a signal, use kill(2). From outside your process (i.e. in some other terminal), use the kill(1) command.

You want to use the Python wrappers of these syscalls. Read about the signal module of Python.

And read Advanced Linux Programming to get a better picture (in your mind) about these issues.

Perhaps the Linux specific timerfd_create(2) could be useful to you (at least if you have some event loop around e.g. poll(2)).

Upvotes: 1

Related Questions