Deadlock error in inserting bulk of records to MySQL database using trigger and Qt multi threading
SET @source_names_id = (select id from source_names USE INDEX (PRIMARY) where source_name=NEW.source_name);


-->

SELECT @source_names_id := id
    FROM source_names
    WHERE source_name = NEW.source_name;


AND have

PRIMARY KEY(id)
INDEX(source_name)


Do not use USE INDEX(PRIMARY) unless it is PRIMARY KEY(source_name).  Even then, there is no need for USE INDEX.

Please provide SHOW CREATE TABLE if you need to discuss this further.