更新- 30/04/19:
谢谢你帮我。我将行更改为queue.Queue(),现在得到以下错误:
$ python3 netgrafio1.py
2019-04-30 16:58:45,470 - DEBUG - [asyncio] - Using selector: EpollSelector
2019-04-30 16:58:45,472 - INFO - [WebSocketServer] - Starting WebSocket server on port 8080
2019-04-30 16:58:45,472 - INFO - [WebSocketServer] - Start collector server
2019-04-30 16:58:45,473 - INFO - [WebSocketServer] - Waiting for incoming data ...
2019-04-30 16:58:45,477 - INFO - [WebServer] - Listening on 5000
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/home/ubuntu/netgrafio/lib/WebServer.py", line 114, in start_server
http_server = Thread(target=IOLoop.instance().start)
File "/home/ubuntu/.local/lib/python3.5/site-packages/tornado/ioloop.py", line 201, in instance
return IOLoop.current()
File "/home/ubuntu/.local/lib/python3.5/site-packages/tornado/ioloop.py", line 265, in current
loop = asyncio.get_event_loop()
File "/usr/lib/python3.5/asyncio/events.py", line 632, in get_event_loop
return get_event_loop_policy().get_event_loop()
File "/usr/lib/python3.5/asyncio/events.py", line 578, in get_event_loop
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-3'.
Traceback (most recent call last):
File "netgrafio1.py", line 100, in <module>
main(parse_args(sys.argv[1:]))
File "netgrafio1.py", line 95, in main
tcp_server = JSONServer(host, int(params.tcp_port), in_queue)
NameError: name 'JSONServer' is not defined更新- 28/04/19:
新错误:
ubuntu@ip-172-31-11-55:~/netgrafio$ python3 netgrafio1.py
Traceback (most recent call last):
File "netgrafio1.py", line 100, in <module>
main(parse_args(sys.argv[1:]))
File "netgrafio1.py", line 81, in main
in_queue = queue()
TypeError: 'module' object is not callable我试图运行一个脚本,遵循netgrafio的这链接。注意,netgrafio1.py是我编辑的试图修复导入的版本。
这是netgrafio1.py的内容:
import sys
import argparse
import logging
try:
import queue
except ImportError:
import Queue as queue
# Local packages
#from lib.TCPServer import JSONServer
from lib.WebSocketServer import WebSocketServer
from lib.WebServer import WebServer
try:
import SocketServer as socketserver
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
except ImportError:
import socketserver
from http.server import HTTPServer, BaseHTTPRequestHandler
def parse_args(params):
""" Parse cmd line arguments """
parser = argparse.ArgumentParser(
description="netgrafio - visualize your network",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Set parameters
parser.add_argument("--tcp-port", action="store", type=int,
help="Specify TCP port to listen for JSON packets", default=8081)
parser.add_argument("--ws-port", action="store", type=int,
help="Specify WebSocket port to send JSON data to", default=8080)
parser.add_argument("--web-port", action="store", type=str,
help="Specify web port to server web application", default=5000)
parser.add_argument("--host", action="store", default="127.0.0.1",
help="Specify host to bind socket on")
args = parser.parse_args(params)
return args
def main(params):
# Global logging settings
logging.basicConfig(level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - [%(name)s] - %(message)s")
# Init in queue (producer and consumer pattern)
in_queue = Queue()
# Set default host
host = params.host
# Start WebSocket server
websocket_server = WebSocketServer(host, int(params.ws_port), in_queue)
websocket_server.start()
# Start Web Server
web_server = WebServer(host, int(params.web_port))
web_server.start()
# Start JSON server
tcp_server = JSONServer(host, int(params.tcp_port), in_queue)
tcp_server.start()
if __name__ == "__main__":
main(parse_args(sys.argv[1:]))
# EOF当我运行这个命令时:
python netgrafio1.py -h我知道这个错误:
Traceback (most recent call last):
File "netgrafio1.py", line 44, in <module>
from lib.WebSocketServer import WebSocketServer
File "/home/ubuntu/netgrafio/lib/WebSocketServer.py", line 54, in <module>
from queue import Queue当我运行这个命令时:
python3 netgrafio1.py我知道这个错误:
Traceback (most recent call last):
File "netgrafio1.py", line 44, in <module>
from lib.WebSocketServer import WebSocketServer
File "/home/ubuntu/netgrafio/lib/WebSocketServer.py", line 46, in <module>
import tornado.web
ImportError: No module named 'tornado'请注意,我确实安装了龙卷风:
pip list | grep tor
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
tornado 5.1.1 我正在尝试让netgrafio运行,所以我得到了这个:
$ python netgrafio.py -h
usage: netgrafio.py [-h] [--tcp-port TCP_PORT] [--ws-port WS_PORT]
[--web-port WEB_PORT] [--host HOST]
netgrafio - visualize your network
optional arguments:
-h, --help show this help message and exit
--tcp-port TCP_PORT Specify TCP port to listen for JSON packets (default:
8081)
--ws-port WS_PORT Specify WebSocket port to send JSON data to (default:
8080)
--web-port WEB_PORT Specify web port to server web application (default:
5000)
--host HOST Specify host to bind socket on (default: 127.0.0.1)发布于 2019-04-28 06:11:43
使用python ...命令时,操作系统可能正在运行Python2.7。在Python2.7中,没有queue模块。在v2.7中,它被称为Queue。它被重命名为queue in v3。
运行python3 ...时,操作系统运行的是Python3.x。尽管这个版本有queue模块,但是您还没有安装用于Python3的ToronaforPython3。
要解决这个问题,请安装用于Python 3的“旋风”:
pip3 install tornado然后使用python3 ...命令运行脚本。
与新错误相关的更新。
queue不是可调用的对象;它是一个模块(即python文件)。请查看queue模块的文档。您需要在代码中使用queue.Queue。
in_queue = queue.Queue()https://stackoverflow.com/questions/55887312
复制相似问题