Maven对原始Spring Boot JAR的依赖[重复](Maven dependency on original Spring Boot JAR [duplicate])
这个问题在这里已有答案:
我正在使用Spring Boot和spring boot maven插件创建一个JAR
插件创建的JAR将类放在JAR的子目录中,这意味着我不能将JAR用作maven中的依赖项。
有没有办法在原始JAR上声明maven中的依赖性。 我看到
target
目录中有一个*.jar.original
文件,所以也许我可以通过声明类型test-jar
的依赖关系来创建对测试类的依赖关系。只是为了澄清:我正在进行此测试/更容易调试,而不是用于生产。
This question already has an answer here:
I'm using Spring Boot with the spring boot maven plugin which creates a JAR with
The JAR created by the plugin puts the classes in subdirectory in the JAR which means that I can't use the JAR as a dependency in maven.
Is there a way to declare a depenency in maven on the original JAR. I see that there is a
*.jar.original
file in thetarget
directory so maybe I can create a dependency on that in the way it's possible to create a dependency on the test classes by declaring a dependency of the kindtest-jar
.Just for clarification: I'm doing this testing/easier debugging, not for production.
原文:
最满意答案
只需使用
try: ... except: ...
块即可。 如果有些奇怪的事情导致线程失败,很可能在你的代码的某个地方抛出一个错误(而不是在线程子系统本身)。 这样你可以捕捉它,记录它,然后重新启动线程。 无论您是想要关闭线程并启动一个新线程,还是只将try/except
块放在while
循环中,以便同一线程继续运行,这都是您的呼叫。另一个解决方案,如果你怀疑可能发生的事情,你无法通过Python的错误处理机制检测到,那就是启动一个监视器线程,定期检查其他线程是否正常运行。
Just use a
try: ... except: ...
block in therun
method. If something weird happens that causes the thread to fail, it's highly likely that an error will be thrown somewhere in your code (as opposed to in the threading subsystem itself); this way you can catch it, log it, and restart the thread. It's your call whether you want to actually shut down the thread and start a new one, or just enclose thetry/except
block in awhile
loop so the same thread keeps running.Another solution, if you suspect that something really weird might happen which you can't detect through Python's error handling mechanism, would be to start a monitor thread that periodically checks to see that the other threads are running properly.
相关问答
更多-
首先,您实际上需要保存所有这些thread对象以在它们上调用join() 。 正如所写,你只保存最后一个,然后只有没有例外。 执行多线程编程的简单方法是为每个线程提供运行所需的所有数据,然后让它不写入该工作集以外的任何内容。 如果所有线程遵循该指导原则,他们的写作不会互相干扰。 然后,一旦一个线程完成,让主线程只将结果聚合成一个全局数组。 这被称为“分叉/连接并行”。 如果您创建了Thread对象的子类,则可以给它留出空间来存储该返回值,而不会干扰其他线程。 然后你可以做这样的事情: class MyThr ...
-
Python:套接字和线程?(Python: Socket and threads?)[2022-06-28]
不幸的是,多线程共享的套接字不是线程安全的。思考缓冲区,两个线程无锁地操作。 正常的实现方式是使用两个套接字,就像ftp.cmd套接字和msg套接字一样。 如果你想通过一个套接字来实现这一点,你可以把不同类型的消息放到不同的队列中,并且第三个线程使用队列并通过唯一套接字发送它们。 通过这种方式,你可以控制心跳信号msg priory到数据msg。 Unfortunately,The socket shared by multi-thread is not thread safe.Think about bu ... -
处理python线程(Handling python threads)[2021-09-10]
使用threading.Event而不是布尔值。 它的构建由多线程监控。 在这个例子中, task_a和task_a_monitor运行不同的费率,但等待相同的事件。 主线程通过set和clear方法来控制它们。 我包含一个布尔值,用于告诉线程他们的工作已经完成并且需要退出时间 - 但是只有在事件设置时才会有影响。 import threading import time # use to start/pause/exit task task_event = threading.Event() task_ ... -
在Python中使用多个线程(using multiple threads in Python)[2022-04-23]
对于你的特定任务,我会推荐一个多处理工作者池 。 您只需定义一个池,然后告诉它要使用多少个进程(默认情况下每个处理器核心一个)以及要在每个工作单元上运行的函数。 然后,您准备好列表中的每个工作单元 (在您的情况下,这将是一个URL列表)并将其提供给工作人员池。 您的输出将是您原始数组中每项工作的工作函数返回值的列表。 所有酷酷的多处理善良都会在后台发生。 当然,还有其他与工作人员合作的方式,但这是我最喜欢的方式。 快乐的多处理! For your specific task I would recommen ... -
python线程和套接字(python threads & sockets)[2023-06-26]
Python使用“真实”线程,即底层平台的线程。 在Linux上,它将使用pthread库(如果你感兴趣, 这里是实现 )。 Python的线程有什么特别之处:GIL:如果一个线程拥有这个全局锁,它就只能修改Python数据结构。 因此,许多Python操作无法使用多个处理器内核。 具有阻塞套接字的线程不会保留GIL,所以它不会影响其他线程。 GIL经常被误解,让人们认为Python中的线程几乎是无用的。 GIL唯一防止的是在多个处理器内核上同时执行“纯”Python代码。 如果您使用线程来创建GUI响应或 ... -
multiprocessing模块和subprocess进程模块都产生了threading.Thead内部的threading.Thead对象可以帮助处理它们产生的进程的I / O。 具体来说,一旦实例化multiprocessing.Pool ,就会生成三个线程 : class Pool(object): ''' Class which supports an async version of the `apply()` builtin ''' Process = Pro ...
-
您可以使用threading.enumerate()访问所有当前线程对象,例如 for thread in threading.enumerate(): print(thread.name) You can access all current thread objects using threading.enumerate(), e.g. for thread in threading.enumerate(): print(thread.name)
-
自我修复的Python线程(Self-repairing Python threads)[2023-06-07]
只需使用try: ... except: ...块即可。 如果有些奇怪的事情导致线程失败,很可能在你的代码的某个地方抛出一个错误(而不是在线程子系统本身)。 这样你可以捕捉它,记录它,然后重新启动线程。 无论您是想要关闭线程并启动一个新线程,还是只将try/except块放在while循环中,以便同一线程继续运行,这都是您的呼叫。 另一个解决方案,如果你怀疑可能发生的事情,你无法通过Python的错误处理机制检测到,那就是启动一个监视器线程,定期检查其他线程是否正常运行。 Just use a try: . ... -
你考虑过GIL(Global Interpreter lock)吗? https://wiki.python.org/moin/GlobalInterpreterLock Python有一个GIL,它不允许从一个进程运行多个线程。 运行代码时,它将作为python进程运行。 您正在尝试从python中不允许的同一进程启动线程。 如果要并行执行某些操作,多处理包是一个不错的选择。 https://pymotw.com/2/multiprocessing/basics.html Have you conside ...
-
PyPy的Python和线程?(Python and Threads with PyPy?)[2022-07-13]
Pypy不会解决每次运行单线程的Python问题,因为它也使用了GIL - http://doc.pypy.org/en/latest/faq.html#does-pypy-have-a -GIL,为什么 除此之外,Kivy是一个嵌入Python本身的复杂项目 - 尽管我不太了解它,但我怀疑是否有可能将其中使用的Python切换为Pypy。 根据您正在做的事情,您可能希望使用multiprocessing模块而不是threading - 它是一个替代品,可以对Python函数进行透明的进程间调用,因此可以利 ...