- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在尝试了解操作系统概念和 Python 库。
我遇到了 Python 文档中提到的一个特定示例 https://docs.python.org/3/library/signal.html在 Windows 上对我不起作用的链接。
import signal, os
def handler(signum, frame):
print('Signal handler called with signal', signum)
raise OSError("Couldn't open device!")
# Set the signal handler and a 5-second alarm
signal.signal(signal.SIGALRM, handler)
signal.alarm(5)
# This open() may hang indefinitely
fd = os.open('/dev/ttyS0', os.O_RDWR)
signal.alarm(0) # Disable the alarm
singal.SIGALRM 不能在 Windows 上运行有什么具体原因吗?
自动完成甚至在 Pycharm IDE 中显示 SIGALRM(我假设如果这样显示,将会有一个变量或函数)。
但是当我运行该程序时,在 Windows 上出现以下错误。我还没有在 Linux 上检查过这个。
Traceback (most recent call last):
File "C:/Users/preddy53/Desktop/syst.py", line 8, in <module>
signal.signal(signal.SIGALRM, handler)
AttributeError: module 'signal' has no attribute 'SIGALRM'
我哪里做错了?它仅特定于操作系统吗?
最佳答案
Is there any specific reason why singal.SIGALRM is not working on windows?
是的,Windows 操作系统没有实现该信号。 example you found开始于:
Here is a minimal example program. It uses the
alarm()
function to limit the time spent waiting to open a file; [...]
和 signal.alarm()
function记录为:
Availability: Unix.
接下来,模块文档页面上其他地方的 SIG*
部分指出:
Note that not all systems define the same set of signal names; only those names defined by the system are defined by this module.
因此 SIGALRM
在 Windows 上不可用,因此您会得到一个属性错误。
请注意,Windows 也没有 /dev
虚拟文件系统,因此 os.open('/dev/ttyS0', os.O_RDWR)
调用将失败也是。
参见 python: windows equivalent of SIGALRM使用线程的替代方法。
关于python - 为什么 signal.SIGALRM 在 Windows 上的 Python 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52779920/
我正在尝试编写一个基准测试来接收来自内核的信号,告诉它调整其参数。我正在尝试研究主动或被动方法是否最有效。 在主动方法中,我使用 setitimer 定期设置警报并强制基准测试查看其目前的性能并重新调
我有一个我自己似乎无法解决的问题。我正在编写一个小的 python 脚本,我想知道为什么我的 signal.alarm 在它所在的函数返回后仍然有效。这是代码: class AlarmExceptio
achul@achul:~/chennai/linux/SM_practise$ cat doubt.c #include #include main() { int ret; pri
我们正在尝试使用 sigaction 和 setitimer 从我们的三个函数中的 while(1) 循环中获取控制权,我们现在面临的问题是仅生成一次 SIGALRM,而下一次它不会生成,即我们能够从
我是信号的新手,我正在尝试在 UDP 回显服务上设置 SIGALRM,作为套接字编程实践。 所以这里我有一个 UDP 套接字,客户端向服务器发送一个字符串并等待响应(任何响应,这里的字符串由服务器回显
我是一个非常初级的程序员,我正在 Ubuntu 中开发客户端服务器程序。这段代码属于我的服务器文件,我想实现一个信号SIGALRM,但我不知道如何才能正确地做到这一点。我的目标是:在我调用信号 ala
我在做作业。 作业是在 Linux 系统(在 Ubuntu 上)上制作虚拟实时操作系统。 我的问题是 SIGALRM,它是调度程序的处理程序。 void scheduler(int signo) {
我是 Linux 信号的新手。如果一个进程初始化多个定时器,那么进程如何知道哪个 SIGALRM 属于哪个定时器? 最佳答案 这取决于您如何设置 SIGALRM 处理程序。 考虑不使用 alarm 而
这段代码有问题.. 我需要等待 (sigwait) 一个过程,直到到达两个信号 SIGUSR1/SIGUSR2 (也许我可以使用 sigalrm 捕捉信号?) #include #include
我需要在超时后中断系统调用(在本例中为 recvfrom)。为此,我正在使用 alarm(),但是生成的 SIGALRM 会终止我的进程,而不仅仅是中断系统调用。 我已经尝试调用 signal(SIG
我在使用 SIGALRM 时遇到了问题。我用它每 3 秒写一次事件进程的 pids。但是一旦它杀死主进程,它就会触发。我做错了什么?一段时间后,我还使用信号杀死每个子进程,我在那里使用 SIGTERM
因此,我尝试调用警报以每秒显示一条消息“仍在工作......”。我包含了 signal.h。 在我的 main 之外,我有我的功能:(我从不为 int 声明/定义 s) void display_me
我编写了这段代码,我必须使用警报信号 (SIGALRM) 让程序打印消息“我还活着”。每 3 秒一次。 但它不起作用,只有当我按下 CTR-C 时它才会发送消息“我还活着”,我猜我没有把 SIGALR
在处理类的系统调用时,我遇到了以下代码的麻烦。无论出于何种原因,当信号处理程序中的 print 语句末尾有换行符时,它会按预期运行,接收和处理信号并显示消息。但是,当换行符不存在时,根本不会显示任何输
我有一个问题。我需要实现一个使用计时器和 SIGALRM 切换 ucontext 线程的程序,但是当我使用 evict_thread 函数切换线程时出现段错误。我相信这是竞争条件的结果,因为它发生在程
所以基本上我的程序中有 4-5 个函数。这是很多行代码,需要从文件中读取和写入,并且可能会以无限循环结束(更糟糕的情况),如果超过 20 秒,我想终止我的程序。下面的代码不起作用,我的程序挂起,操作系
嗨,我正在尝试了解有关信号的更多信息,我编写了一个简单的代码,该代码应该只打印“再见”发送警报信号的所有内容。我正在使用 sigaction 来设置它。但是,我在错误检查中不断返回 NULL,有人可以
我目前正在使用 select() 作为计时器。我有一个循环内发生的网络接收操作,每隔几秒需要发生一个处理操作。 因此,select() 语句的超时不断变化——随时间减少到零,然后从 3 重新开始。 r
好吧,不太确定这是内存损坏还是只是我的代码中的错误,但这是问题的描述:单线程程序注册一个SIGALRM处理程序: struct sigaction action; sigset_t blocked;
我有一个 C 程序,如果 n 作为参数传递,它会计算前 n 个素数。 $ ./prime 5 2 3 5 7 11 如果我可以给程序的进程SIGALRM,程序的逻辑允许我进入一个想要的函数。 所以基本
我是一名优秀的程序员,十分优秀!