11# import threading
2- from threading import Thread
3- import socket
42import errno
5- import tempfile
6- import urllib .request
7- import urllib .parse
8- import urllib .error
3+ import logging
94import os
10- from math import ceil
115import queue
12- import logging
6+ import socket
7+ import tempfile
8+ import urllib .error
9+ import urllib .parse
10+ import urllib .request
1311import warnings
1412from collections import namedtuple
13+ from math import ceil
14+ from threading import Thread
15+
16+ from .exception import BQCommError
1517
1618# import numpy as np
1719
18- from .exception import BQCommError
1920
2021try : # checks for lxml if not found uses python xml
2122 from lxml import etree
3637FeatureResource = namedtuple ("FeatureResource" , ["image" , "mask" , "gobject" ])
3738FeatureResource .__new__ .__defaults__ = (None , None , None )
3839
40+
3941class FeatureError (Exception ):
4042 """
4143 Feature Communication Exception
4244 """
4345
46+
4447class Feature (object ):
4548 def fetch (self , session , name , resource_list , path = None ):
4649 """
@@ -74,8 +77,7 @@ def fetch(self, session, name, resource_list, path=None):
7477 query = "&" .join (query )
7578 sub .attrib ["uri" ] = "%s?%s" % (url , query )
7679
77- log .debug ("Fetch Feature %s for %s resources" % (name ,
78- len (resource_list )))
80+ log .debug ("Fetch Feature %s for %s resources" % (name , len (resource_list )))
7981
8082 if path is None :
8183 f = tempfile .NamedTemporaryFile (
@@ -130,8 +132,7 @@ def fetch_vector(self, session, name, resource_list):
130132 status = status [index [0 ]][0 ]
131133 hdf5 .close ()
132134 os .remove (hdf5 .filename ) # remove file from temp directory
133- raise FeatureError ("%s:Error occured during feature calculations"
134- % status )
135+ raise FeatureError ("%s:Error occured during feature calculations" % status )
135136 table = hdf5 .root .values
136137 # status_table = hdf5.root.status # to get the status
137138 feature_vector = table [:]["feature" ]
@@ -150,8 +151,8 @@ def length(session, name):
150151 @return: feature length
151152 """
152153 xml = session .fetchxml ("/features/%s" % name )
153- return int (xml .find (
154- 'feature/tag[@name="feature_length"]' ). attrib . get ( "value" ))
154+ return int (xml .find ('feature/tag[@name="feature_length"]' ). attrib . get ( "value" ))
155+
155156
156157class ParallelFeature (Feature ):
157158 MaxThread = 8
@@ -200,8 +201,7 @@ def run(self):
200201 else :
201202 break
202203
203- def request_thread_pool (self , request_queue , errorcb = None ,
204- thread_count = MaxThread ):
204+ def request_thread_pool (self , request_queue , errorcb = None , thread_count = MaxThread ):
205205 """
206206 Runs the BQRequestThread
207207
@@ -293,8 +293,7 @@ def fetch(self, session, name, resource_list, path=None):
293293 log .warning ("Warning no resources were provided" )
294294 return
295295
296- log .debug ("Exctracting %s on %s resources" % (name ,
297- len (resource_list )))
296+ log .debug ("Exctracting %s on %s resources" % (name , len (resource_list )))
298297
299298 if path is None :
300299 f = tempfile .TemporaryFile (suffix = ".h5" , dir = tempfile .gettempdir ())
@@ -338,8 +337,7 @@ def run(self):
338337 temp_status_table = hdf5temp .root .status
339338 if not hasattr (hdf5 .root , "values" ):
340339 temp_table .copy (hdf5 .root , "values" )
341- temp_status_table .copy (hdf5 .root ,
342- "status" )
340+ temp_status_table .copy (hdf5 .root , "status" )
343341 else :
344342 table = hdf5 .root .values
345343 status_table = hdf5 .root .status
@@ -420,8 +418,7 @@ def request():
420418 else :
421419 thread_num , chunk_size = self .calculate_request_plan (resource_list )
422420
423- for partial_resource_list in self .chunk (resource_list ,
424- int (chunk_size )):
421+ for partial_resource_list in self .chunk (resource_list , int (chunk_size )):
425422 request_queue .put (request_factory (partial_resource_list ))
426423
427424 w = WriteHDF5Thread (write_queue )
@@ -462,5 +459,4 @@ def fetch_vector(self, session, name, resource_list):
462459
463460 @return: a list of features as numpy array
464461 """
465- return super (ParallelFeature , self ).fetch_vector (session , name ,
466- resource_list )
462+ return super (ParallelFeature , self ).fetch_vector (session , name , resource_list )
0 commit comments