我最近改变了程序的目录布局:之前,我把所有模块放在"main"文件夹中.现在,我已将它们移动到以程序命名的目录中,并放置在__init__.py那里制作包.
现在我在我的主目录中有一个.py文件,用于启动我的程序,这个文件更整洁.
无论如何,尝试加载以前版本的程序中的pickle文件是失败的.我得到了,"ImportError:没有模块命名工具" - 我想这是因为我的模块以前在主文件夹中,现在它在whyteboard.tools中,而不仅仅是简单的工具.但是,在工具模块中导入的代码与它位于同一目录中,因此我怀疑是否需要指定包.
所以,我的程序目录看起来像这样:
whyteboard-0.39.4
-->whyteboard.py
-->README.txt
-->CHANGELOG.txt
---->whyteboard/
---->whyteboard/__init__.py
---->whyteboard/gui.py
---->whyteboard/tools.py
whyteboard.py从whyteboard/gui.py启动一个代码块,启动GUI.在目录重新组织之前,肯定没有发生这种酸洗问题.
尝试使用共享队列同时运行两个不同的函数并获得错误...如何使用共享队列同时运行两个函数?这是Windows 7上的Python 3.6版.
from multiprocessing import Process
from queue import Queue
import logging
def main():
x = DataGenerator()
try:
x.run()
except Exception as e:
logging.exception("message")
class DataGenerator:
def __init__(self):
logging.basicConfig(filename='testing.log', level=logging.INFO)
def run(self):
logging.info("Running Generator")
queue = Queue()
Process(target=self.package, args=(queue,)).start()
logging.info("Process started to generate data")
Process(target=self.send, args=(queue,)).start()
logging.info("Process started to send data.")
def package(self, queue):
while True:
for i in range(16):
datagram = bytearray()
datagram.append(i)
queue.put(datagram)
def send(self, queue):
byte_array = bytearray()
while True:
size_of__queue = queue.qsize()
logging.info(" queue size …Run Code Online (Sandbox Code Playgroud)