Q:

Sending object data from blender with urllib very slow

I am sending object loc rot and scale every keyframe to http address using urllib but the frame rate drops significantly.
Thats the code I am using:
import bpy
import urllib
import mathutils 
from bpy import context
from urllib import request, parse
from math import sin, cos, radians
from mathutils import Matrix

def RunPerFrame(scene):
    for obj in bpy.data.objects:
        mat = bpy.context.object.matrix_world
        loc = mat.to_translation()
        rot = mat.to_3x3().to_quaternion()
        scale = obj.dimensions
        qtX = round(rot.x,3)
        qtY = round(rot.y,3)
        qtZ = round(rot.z,3)
        qtW = round(rot.w,3)
        loX = round(loc.x,3)
        loY = round(loc.y,3)
        loZ = round(loc.z,3)
        scX = round(scale.x,3)
        scY = round(scale.y,3)
        scZ = round(scale.z,3)

    url = ''
    values = { 'msgInstruction=' : 'MOVE_OBJ',
        'rotQuat=' : str(qtX) + ',' + str(qtY) + ',' + str(qtZ) + ',' + str(qtW),
        'objLoc=' : str(loX) + ',' + str(loY) + ',' + str(loZ),
        'objScale=' : str(scX) + ',' + str(scY) + ',' + str(scZ) }

    data = urllib.parse.urlencode(values)
    encoded_data = data.encode('ascii')
    req = urllib.request.Request(url, encoded_data)
    response = urllib.request.urlopen(req)
    the_page = response.read()

bpy.app.handlers.frame_change_pre.append(RunPerFrame)

Currently testing with one object and the frame rate drops below 2 fps
Is there a way to make this faster with this code?

A:

using Mike Pan answer i have tried to split the code and put the networking part on a different thread see if this helps with the speed 
import bpy
import urllib
import mathutils 
from bpy import context
from urllib import request, parse
from math import sin, cos, radians
from mathutils import Matrix

import time
import threading

class Worker(threading.Thread):

    def __init__(self, values):
        self.values = values
        threading.Thread.__init__(self)

    def run(self):
        url = ''
        data = urllib.parse.urlencode(self.values)
        encoded_data = data.encode('ascii')
        req = urllib.request.Request(url, encoded_data)
        response = urllib.request.urlopen(req)
        the_page = response.read()

def RunPerFrame(scene):
    for obj in bpy.data.objects:
        mat = bpy.context.object.matrix_world
        loc = mat.to_translation()
        rot = mat.to_3x3().to_quaternion()
        scale = obj.dimensions
        qtX = round(rot.x,3)
        qtY = round(rot.y,3)
        qtZ = round(rot.z,3)
        qtW = round(rot.w,3)
        loX = round(loc.x,3)
        loY = round(loc.y,3)
        loZ = round(loc.z,3)
        scX = round(scale.x,3)
        scY = round(scale.y,3)
        scZ = round(scale.z,3)

    values = { 'msgInstruction=' : 'MOVE_OBJ','rotQuat=' : str(qtX) + ',' + str(qtY) + ',' + str(qtZ) + ',' + str(qtW),'objLoc=' : str(loX) + ',' + str(loY) + ',' + str(loZ),'objScale=' : str(scX) + ',' + str(scY) + ',' + str(scZ) }  
    thread = Worker(values)
    thread.start()

bpy.app.handlers.frame_change_pre.append(RunPerFrame)

