[英]Python Scheduling jobs with schedule along with socket module not working
我正在尝试创建一个套接字服务器 (TCP/IP) 并在其中基于来自客户端的少量数据我正在安排一些后台作业。
以下代码正在运行->
import schedule
import time
def test1():
print('hi from 1')
def test2():
print('hi from test2')
while True:
schedule.run_pending()
time.sleep(1)
然后我尝试使用套接字服务器执行以下操作,然后它不执行作业/功能。 有人可以帮助我这里发生了什么。
不工作的代码
import schedule
import time
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 8009)
print('starting up on {} port {}'.format(*server_address))
sock.bind(server_address)
# Listen for incoming connections
sock.listen(1)
def test1():
print('hi from 1')
def test2():
print('hi from test2')
schedule.every(1).minutes.do(test1)
schedule.every(2).minutes.do(test2)
while True:
schedule.run_pending()
time.sleep(1)
print('waiting for a connection')
connection, client_address = sock.accept()
data = connection.recv(1024)
result = data.decode('utf-8')
print('data recived from clinet : ', result)
我想要实现的是我想创建 python 套接字服务器,它将接受来自节点客户端的请求,并基于客户端数据我想在 python 中安排一些工作。 为此,我使用套接字,从 python 调度模块来创建套接字服务器并分别调度作业和节点 js 客户端的网络模块,以便将数据发送到 python 服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.