关于如何在Python中使用线程的一般教程或好资源?
何时使用线程,它们如何有效,以及线程的某些一般背景[特定于Python]?
我有一个案例要在我的项目中实施。下面是一个必须实施的示例休息服务
@GET
@Path("/test/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String getData(@PathParam("id") String id) {
//Some processing to get value of String
String result = doSomeProcessing();
//I want to return this result to GUI and call one more rest api
// and end this process without waiting for response from second
//call
new Thread(){
//call second rest api
}.start();
return result;
}
Run Code Online (Sandbox Code Playgroud)
这是使用新线程调用第二个休息 API 并返回结果而不等待第二个休息 API 响应的好方法吗?我还研究了异步 Rest 调用,但它并不完全符合我的要求。请指教。提前致谢