gpt4 book ai didi

python - sikuli python 脚本上的 .sendto() 方法在 Windows 上不起作用

转载 作者:太空狗 更新时间:2023-10-29 21:11:46 27 4
gpt4 key购买 nike

我在 Windows 上开发了一个使用此代码的 sikuli python 脚本:

from socket import AF_INET, SOCK_DGRAM
import sys
import socket
import struct, time

host = "pool.ntp.org"
port = 123
buf = 1024
address = (host,port)
msg = '\x1b' + 47 * '\0'

# reference time (in seconds since 1900-01-01 00:00:00)
TIME1970 = 2208988800L # 1970-01-01 00:00:00

# connect to server
client = socket.socket( AF_INET, SOCK_DGRAM)
client.sendto(msg, address)
msg, address = client.recvfrom( buf )

t = struct.unpack( "!12I", msg )[10]
t -= TIME1970

current_time = time.ctime(t).replace(" "," ")

该代码在 linux 下或在 windows 上的 python 脚本中运行良好,但如果我在 sikulix 上使用此代码在 windows 上它崩溃(在行 => client.sendto(msg, address) ) 并出现以下错误:

[error] script [ Sikuli_Test_Original ] stopped with error in line 23
[error] _socket.error ( [Errno -1] Unmapped exception: java.util.concurrent.RejectedExecutionException: event executor terminated )
[error] --- Traceback --- error source first line: module ( function ) statement 359: _socket ( handle_exception ) _socket.error: [Errno -1] Unmapped exception: java.util.concurrent.RejectedExecutionException: event executor terminated
995: _socket ( sendto ) File "C:\Users\myuser\Documents\Sikuli\sikulix.jar\Lib\_socket.py", line 971, in _datagram_connect
[error] --- Traceback --- end --------------

知道为什么以及如何解决它吗?

最佳答案

您的问题已在讨论 Sikuli 如何与 Jython 互操作的线程中讨论并显然已解决(这似乎是一个 Jython 错误):https://bugs.launchpad.net/sikuli/+bug/1464105

我检查了解决方案;此代码适用于我在 Windows 10 上的 SikuliX IDE 中。技巧基本上在顶部添加的初始化 header 中:

import sys, _socket
from socket import AF_INET, SOCK_DGRAM
if _socket.NIO_GROUP.isShutdown():
print "RE-CREATING NIO_GROUP"
_socket.NIO_GROUP = _socket.NioEventLoopGroup(2, _socket.DaemonThreadFactory("PyScan-Netty-Client-%s"))
sys.registerCloser(_socket._shutdown_threadpool)
import socket
import struct, time

host = "pool.ntp.org"
port = 123
buf = 1024
address = (host,port)
msg = '\x1b' + 47 * '\0'

# reference time (in seconds since 1900-01-01 00:00:00)
TIME1970 = 2208988800L # 1970-01-01 00:00:00
print "Before socket operation"
# connect to server
client = socket.socket( AF_INET, SOCK_DGRAM)
client.sendto(msg, address)
print "After socket operation"
msg, address = client.recvfrom( buf )
t = struct.unpack( "!12I", msg )[10]
t -= TIME1970

current_time = time.ctime(t).replace(" "," ")
print current_time

关于python - sikuli python 脚本上的 .sendto() 方法在 Windows 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47252641/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com