gRPCClient.jl icon indicating copy to clipboard operation
gRPCClient.jl copied to clipboard

Threads@spawn cause error.

Open deahhh opened this issue 3 years ago • 0 comments

Thanks for the work. my env is julia 1.8.2

syntax = "proto3";

package Embedder;
// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc embed_img (FImage) returns (Embedding) {}
}

// The request message containing the user's name.
message FImage {
  bytes fimg = 1;
}

// The response message containing the greetings
message Embedding {
  repeated float embedding = 1;
}

this grpc server accept Vector{UInt8} as file of image, and process it and return an 256d vector. while start with -t 6, the client print gRPCServiceCallException: 12, "b'/Embedder.Greeter/embed_img'" requires exactly one request message.

the error disappear imediatly after replacing Threads.@spawn with @async.

the client code is:

include("EmbedderClients.jl")

function create()
    client = EmbedderClients.GreeterBlockingClient("localhost:15001")
    extract_feature(fimg::String) = EmbedderClients.embed_img(client, EmbedderClients.Embedder.FImage(; fimg=read(fimg)))[1].embedding
end

extractor = create()

Threads.@spawn try
    ft = extractor("/data/data_pull/label_data/public/img/tolabel/1.jpg")
    println(ft)
    ft = extractor("/data/data_pull/label_data/public/img/tolabel/10.jpg")
    println(ft)
    ft = extractor("/data/data_pull/label_data/public/img/tolabel/10000.jpg")
    println(ft)
    
catch e
    println(e)
end

deahhh avatar Nov 17 '22 10:11 deahhh