Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
8f3b6bc2
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8f3b6bc2
编写于
1月 05, 2011
作者:
C
Cole Robinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
event-test: Simplify debug on/off
Make it easy to change debugging if being used by a client program.
上级
1dd5c7f2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
18 deletion
+19
-18
examples/domain-events/events-python/event-test.py
examples/domain-events/events-python/event-test.py
+19
-18
未找到文件。
examples/domain-events/events-python/event-test.py
浏览文件 @
8f3b6bc2
...
...
@@ -15,6 +15,12 @@ import errno
import
time
import
threading
do_debug
=
False
def
debug
(
msg
):
global
do_debug
if
do_debug
:
print
msg
#
# This general purpose event loop will support waiting for file handle
# I/O and errors events, as well as scheduling repeatable timers with
...
...
@@ -83,8 +89,7 @@ class virEventLoopPure:
self
.
opaque
[
1
])
def
__init__
(
self
,
debug
=
False
):
self
.
debugOn
=
debug
def
__init__
(
self
):
self
.
poll
=
select
.
poll
()
self
.
pipetrick
=
os
.
pipe
()
self
.
nextHandleID
=
1
...
...
@@ -106,13 +111,9 @@ class virEventLoopPure:
# with the event loop for input events. When we need to force
# the main thread out of a poll() sleep, we simple write a
# single byte of data to the other end of the pipe.
self
.
debug
(
"Self pipe watch %d write %d"
%
(
self
.
pipetrick
[
0
],
self
.
pipetrick
[
1
]))
debug
(
"Self pipe watch %d write %d"
%
(
self
.
pipetrick
[
0
],
self
.
pipetrick
[
1
]))
self
.
poll
.
register
(
self
.
pipetrick
[
0
],
select
.
POLLIN
)
def
debug
(
self
,
msg
):
if
self
.
debugOn
:
print
msg
# Calculate when the next timeout is due to occurr, returning
# the absolute timestamp for the next timeout, or 0 if there is
...
...
@@ -166,7 +167,7 @@ class virEventLoopPure:
def
run_once
(
self
):
sleep
=
-
1
next
=
self
.
next_timeout
()
self
.
debug
(
"Next timeout due at %d"
%
next
)
debug
(
"Next timeout due at %d"
%
next
)
if
next
>
0
:
now
=
int
(
time
.
time
()
*
1000
)
if
now
>=
next
:
...
...
@@ -174,7 +175,7 @@ class virEventLoopPure:
else
:
sleep
=
(
next
-
now
)
/
1000.0
self
.
debug
(
"Poll with a sleep of %d"
%
sleep
)
debug
(
"Poll with a sleep of %d"
%
sleep
)
events
=
self
.
poll
.
poll
(
sleep
)
# Dispatch any file handle events that occurred
...
...
@@ -188,7 +189,7 @@ class virEventLoopPure:
h
=
self
.
get_handle_by_fd
(
fd
)
if
h
:
self
.
debug
(
"Dispatch fd %d handle %d events %d"
%
(
fd
,
h
.
get_id
(),
revents
))
debug
(
"Dispatch fd %d handle %d events %d"
%
(
fd
,
h
.
get_id
(),
revents
))
h
.
dispatch
(
self
.
events_from_poll
(
revents
))
now
=
int
(
time
.
time
()
*
1000
)
...
...
@@ -201,7 +202,7 @@ class virEventLoopPure:
# Deduct 20ms, since schedular timeslice
# means we could be ever so slightly early
if
now
>=
(
want
-
20
):
self
.
debug
(
"Dispatch timer %d now %s want %s"
%
(
t
.
get_id
(),
str
(
now
),
str
(
want
)))
debug
(
"Dispatch timer %d now %s want %s"
%
(
t
.
get_id
(),
str
(
now
),
str
(
want
)))
t
.
set_last_fired
(
now
)
t
.
dispatch
()
...
...
@@ -230,7 +231,7 @@ class virEventLoopPure:
self
.
poll
.
register
(
fd
,
self
.
events_to_poll
(
events
))
self
.
interrupt
()
self
.
debug
(
"Add handle %d fd %d events %d"
%
(
handleID
,
fd
,
events
))
debug
(
"Add handle %d fd %d events %d"
%
(
handleID
,
fd
,
events
))
return
handleID
...
...
@@ -247,7 +248,7 @@ class virEventLoopPure:
self
.
timers
.
append
(
h
)
self
.
interrupt
()
self
.
debug
(
"Add timer %d interval %d"
%
(
timerID
,
interval
))
debug
(
"Add timer %d interval %d"
%
(
timerID
,
interval
))
return
timerID
...
...
@@ -260,7 +261,7 @@ class virEventLoopPure:
self
.
poll
.
register
(
h
.
get_fd
(),
self
.
events_to_poll
(
events
))
self
.
interrupt
()
self
.
debug
(
"Update handle %d fd %d events %d"
%
(
handleID
,
h
.
get_fd
(),
events
))
debug
(
"Update handle %d fd %d events %d"
%
(
handleID
,
h
.
get_fd
(),
events
))
# Change the periodic frequency of the timer
def
update_timer
(
self
,
timerID
,
interval
):
...
...
@@ -269,7 +270,7 @@ class virEventLoopPure:
h
.
set_interval
(
interval
);
self
.
interrupt
()
self
.
debug
(
"Update timer %d interval %d"
%
(
timerID
,
interval
))
debug
(
"Update timer %d interval %d"
%
(
timerID
,
interval
))
break
# Stop monitoring for events on the file handle
...
...
@@ -278,7 +279,7 @@ class virEventLoopPure:
for
h
in
self
.
handles
:
if
h
.
get_id
()
==
handleID
:
self
.
poll
.
unregister
(
h
.
get_fd
())
self
.
debug
(
"Remove handle %d fd %d"
%
(
handleID
,
h
.
get_fd
()))
debug
(
"Remove handle %d fd %d"
%
(
handleID
,
h
.
get_fd
()))
else
:
handles
.
append
(
h
)
self
.
handles
=
handles
...
...
@@ -290,7 +291,7 @@ class virEventLoopPure:
for
h
in
self
.
timers
:
if
h
.
get_id
()
!=
timerID
:
timers
.
append
(
h
)
self
.
debug
(
"Remove timer %d"
%
timerID
)
debug
(
"Remove timer %d"
%
timerID
)
self
.
timers
=
timers
self
.
interrupt
()
...
...
@@ -329,7 +330,7 @@ class virEventLoopPure:
# This single global instance of the event loop wil be used for
# monitoring libvirt events
eventLoop
=
virEventLoopPure
(
debug
=
False
)
eventLoop
=
virEventLoopPure
()
# This keeps track of what thread is running the event loop,
# (if it is run in a background thread)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录