def handle(self, *args, **options): self.build_id = 'build-%s' % now # send the end signal signals.build_item_commence.send(sender=self, thread=thread.get_ident()) generate_screenshot = True if options['generate'] in ['True',True] else False all_pages = True if options['all'] in ['True',True] else False num_pages_ids = len(args) logger.debug('num num_pages_ids %d' % num_pages_ids) if all_pages in ['False',False] and num_pages_ids == 0: raise CommandError('Please specify page_id(s) to test in form: tailor_run_layout_test <id> <id> <id> ...') self.spindle = Spindle(capture=generate_screenshot, output_path=OUTPUT_PATH) if all_pages == True: args = [] for page in Page.objects.all(): self.test_page(url=page.url, elements_list=page.get_test_elements(), page=page) else: for page_id in args: try: page = Page.objects.get(pk=int(page_id)) except Page.DoesNotExist: raise CommandError('Page "%s" does not exist' % page_id) self.test_page(url=page.url, elements_list=page.get_test_elements(), page=page) self.spindle.driver.close() self.spindle.driver.quit() # send the end signal signals.build_item_complete.send(sender=self, thread=thread.get_ident())
def handle(self): """Handle the communication.""" print 'Accepting the connection %x from %s:%d' % ( thread.get_ident(), self.request.getpeername()[0], self.request.getpeername()[1]) self.request.settimeout(30) try: try: rbuffer = self.request.recv(1024) except socket.timeout: print 'The connection %s timed out - closing' % thread.get_ident() try: self.request.close() except: pass return else: sbuffer = self.session.process(rbuffer) self.request.sendall(sbuffer) except Exception, e: try: self.request.close() except: pass print '%s.\nConnection %x closed' % (e, thread.get_ident()) return
def do_post(self, url, u, request, settings={}, https=True): u = u.replace(" ", "%20") if DEBUG: logging.debug("*** POST *** (thr: %s, t: %s) %s" % (thread.get_ident(), ` int(time.time()) `, url + u)) else: logging.info("*** POST *** %s" % url + u) params = self.anystring_as_utf8(request) if params: logging.debug("params: %s" % params) api_qa_cert = os.getenv("PYTAF_HOME") + "/resources/cert.pem" CERT_FILE = settings.get("cert_file", api_qa_cert) # os.getenv("TEST_HOME") + "/resources/cert.pem" headers = self.get_headers(url, request, settings) logging.info("headers = %s:" % headers) if https == True: conn = httplib.HTTPSConnection(url, cert_file=CERT_FILE) else: conn = httplib.HTTPConnection(url) start_time = time.time() conn.request("POST", u, params, headers) response = conn.getresponse() end_time = time.time() logging.debug("%s, %s" % (response.status, response.reason)) logging.debug( "http response time: (thr: %s, t: %s)" % (thread.get_ident(), round(float(end_time - start_time), 2)) ) d = response.read().decode() # read() returns a bytes object logging.debug("%s" % d) return {"data": d, "status": response.status, "reason": response.reason}
def getValue(key): """Get the dynamic value of `key`""" try: value = values[key] except KeyError: this_thread = get_ident() rule = getRule(key) # this ensures distances[key] is known stack = set_stack(this_thread, []) stack.append(distances[key]) try: value = key.__apply__(key, rule) finally: distance = stack.pop() if not stack: del computing[this_thread] else: stack[-1] = min(stack[-1], distance) value = publish(distance, key, value) else: if computing: stack = get_stack(get_ident()) if stack: stack[-1] = min(stack[-1], distances[key]) return value
def get_session(self, session_id=''): """Return an existing or new client Session.""" logger.debug("LOOKING FOR SESSION %s" % session_id) exists = self.sessions.session_exists(session_id) if exists: logger.debug('session exists') else: logger.debug('session does not exist') logger.debug('existing sessions are %s' \ % self.sessions.get_session_ids()) session = self.sessions.get(session_id) if session is None: logger.debug("session doesn't exist locally") session = self.sessions.add_session(self) logger.debug("Thread %s - created session %s" % (get_ident(), str(session))) if exists: session.incr_hits() else: logger.debug("Thread %s - reusing same session %s" % (get_ident(), str(session))) session.incr_hits() return session
def run(self): print "run" while 1: self.emit("now", "now", str(thread.get_ident())) GObject.idle_add(self.emit, "idle", "idle", str(thread.get_ident())) time.sleep(1)
def execute(self, *args, **kwargs): global db if debug_cursors and self.c in c_closed: print >> param.log, 'INVALID CURSOR USE FOR %r' % self.c print >> param.log, 'Cursor alloc call was in:\n' print >> param.log, '-' * 78 print >> param.log, ''.join(c_opened[self.c]) print >> param.log, 'Cursor close call was in:\n' print >> param.log, '-' * 78 print >> param.log, ''.join(c_closed[self.c]) # SQLite3 can deadlock when multiple writers collide, so we use a lock to # prevent this from happening if args[0].split()[0].lower() in ['insert', 'update', 'delete', 'create'] \ and not self.locked: db.acquire() before = time.time() if param.debug: print >> param.log, thread.get_ident(), time.time(), args backoff = 0.1 done = False while not done: try: result = self.c.execute(*args, **kwargs) done = True except sqlite.OperationalError, e: if param.debug: print >> param.log, thread.get_ident(), time.time(), str(e), print >> param.log, 'sleeping for', backoff time.sleep(backoff) backoff = min(backoff * 2, 5.0)
def get_user_info_from_ldap(nickname="", email="", ccid=""): """Query the CERN LDAP server for information about a user. Return a dictionary of information""" try: connection = _ldap_connection_pool[get_ident()] except KeyError: connection = _ldap_connection_pool[get_ident()] = _cern_ldap_login() if nickname: query = '(displayName=%s)' % nickname elif email: query = '(mail=%s)' % email elif ccid: query = '(employeeID=%s)' % ccid else: return {} try: result = connection.search_st(CFG_CERN_LDAP_BASE, ldap.SCOPE_SUBTREE, query, timeout=5) if result and nickname: return result else: try: return result[0][1] except IndexError: return {} except ldap.TIMEOUT: pass return {}
def begin_txn(self): """ Start a bsddb transaction. If the current thread already has a running transaction, a nested transaction with the first transaction for this thread as parent is started. See: http://pybsddb.sourceforge.net/ref/transapp/nested.html for more on nested transactions in BDB. """ # A user should be able to wrap several operations in a transaction. # For example, two or more adds when adding a graph. # Each internal operation should be a transaction, e.g. an add # must be atomic and isolated. However, since add should handle # BDB exceptions (like deadlock), an internal transaction should # not fail the user transaction. Here, nested transactions are used # which have this property. txn = None try: if not thread.get_ident() in self.__dbTxn and self.is_open() and not self.__closing: self.__dbTxn[thread.get_ident()] = [] # add the new transaction to the list of transactions txn = self.db_env.txn_begin() self.__dbTxn[thread.get_ident()].append(txn) else: # add a nested transaction with the top one as parent txn = self.db_env.txn_begin(self.__dbTxn[thread.get_ident()][0]) self.__dbTxn[thread.get_ident()].append(txn) except Exception, e: print "begin_txn: ", e if txn != None: txn.abort()
def run(self): """ """ if not self.head: while True: # if a worker is head it should not has # consume method, vise versa. # hence the if here sees to be redundant # # if block at consume func, working is False. # TODO: self.working is a critical area. make it # atomic. item = self.consume() logging.info(' %d: start working' % thread.get_ident()) self.working = True ret = self.func(item) if not self.produce is None: self.produce(ret) self.working = False logging.info(' %d: end working' % thread.get_ident()) else: if not self.produce is None: for item in self.func(): self.produce(item)
def stemWords(words, lang): """Return WORDS stemmed according to language LANG (e.g. 'en').""" if lang == 'en' and _stemmers and _stemmers.has_key(get_ident()): #make sure _stemmers[get_ident()] is avail.. return [_stemmers[get_ident()].stem(word, 0, len(word)-1) for word in words] else: return words
def save_data(self, environ, start, stop, collector): data = {} data['hostname'] = self.hostname data['environ'] = dict((k, v) for k, v in environ.iteritems() if isinstance(v, basestring)) data['start_time'] = start data['stop_time'] = stop data['thread_ident'] = thread.get_ident() # Only take the 25 most frequent stack frames collector.filter(25) samples = [] for stack, frequency in collector.stack_counts.iteritems(): frames = [] for elm in stack: frame = {} frame['file'] = elm[0] frame['line_no'] = elm[1] frame['function'] = elm[2] frames.append(frame) sample = {} sample['frames'] = frames sample['frequency'] = frequency samples.append(sample) data['samples'] = samples filename = '%s-%s' % (time.time(), thread.get_ident()) if not os.path.exists(self.outpath): os.makedirs(self.outpath) with open(os.path.join(self.outpath, filename + '.json'), 'w') as fp: json.dump(data, fp, indent=2)
def acquire(self, flag=1): """Acquire the lock. If the optional flag argument is false, returns immediately when it cannot acquire the __wait lock without blocking (it may still block for a little while in order to acquire the __mutex lock). The return value is only relevant when the flag argument is false; it is 1 if the lock is acquired, 0 if not. """ self.__mutex.acquire() try: if self.__tid == thread.get_ident(): self.__count = self.__count + 1 return 1 finally: self.__mutex.release() locked = self.__wait.acquire(flag) if not flag and not locked: return 0 try: self.__mutex.acquire() assert self.__tid == None assert self.__count == 0 self.__tid = thread.get_ident() self.__count = 1 return 1 finally: self.__mutex.release()
def Checkout(tag, module_list, repository_name = "", az = None, timestamp = None, nonrecursive = 0, zap = None): log.trace( 'entry' , [ module_list , repository_name , az , timestamp , nonrecursive , zap ] ) module_list = listify(module_list) if cvs_checkout_hook: module_list = cvs_checkout_hook(tag, module_list, repository_name, az, timestamp, nonrecursive) if not module_list: return if zap: for mod in module_list: if az: mod = az if os.path.exists(mod): import thread print "DELETING: %s [%d] START" % (mod, thread.get_ident()) shell.rm(mod) print "DELETING: %s [%d] END" % (mod, thread.get_ident()) log.trace( 'exit' ) return Get(repository_name).Checkout(tag, module_list, az, timestamp, nonrecursive)
def ParallelThread(): for _ in xrange(self.OPEN_WITH_LOCK_TRIES_PER_THREAD): t = time.time() try: with aff4.FACTORY.OpenWithLock( self.client_urn, token=self.token, blocking=True, blocking_sleep_interval=self.OPEN_WITH_LOCK_SYNC_LOCK_SLEEP, blocking_lock_timeout=10): # We fail if another thread has the object already opened here. if self.opened: self.open_failures += 1 self.fail("Double open!") self.opened = True logging.info("Thread %s holding lock for 0.5 seconds.", thread.get_ident()) time.sleep(0.5) # We fail if someone has closed the object while we are holding it # opened. if not self.opened: self.close_failures += 1 self.fail("Double close!") self.results.append(thread.get_ident()) self.opened = False return except aff4.LockError: logging.info("Lock failed after %s seconds - retying.", (time.time() - t))
def testDoubleCallbackToPython(self): """Test a call to managed code that then calls back into Python that then calls managed code that then calls Python again.""" dprint("thread %s DoubleCallBack" % thread.get_ident()) result = ThreadTest.CallEchoString2("spam") self.failUnless(result == "spam") dprint("thread %s DoubleCallBack ret" % thread.get_ident())
def __delitem__(self, key, pys=False): logging.debug("Removing Object from World %s [%d]", repr(key), thread.get_ident()) # Notify each item this may be in that it's no longer colliding # HACK: Get around issue with PyMunk not telling us shapes when object removed already before separate callback if len(key.in_celestialbody) > 0: for item in key.in_celestialbody[:]: item.collide_end(key) logging.debug("SEMAPHORE ACQ delitem [%d]", thread.get_ident()) self.__addremovesem.acquire() if self.__objects.has_key(key.id): if pys: key.removeFromSpace(self.__space) elif key in self.__toadd: self.__toadd.remove(key) else: self.__toremove.append(key) del self.__objects[key.id] if key in self.__influential: self.__influential.remove(key) self.__addremovesem.release() logging.debug("SEMAPHORE REL delitem [%d]", thread.get_ident()) # Notify after removed, in case re-add same object for objListener in self.__objectListener: objListener(key, False)
def append(self, item, pys=False): """ Call to add an object to the game world from threads outside the game loop """ logging.debug("Append Object to World %s [%d]", repr(item), thread.get_ident()) for objListener in self.__objectListener: objListener(item, True) logging.debug("SEMAPHORE ACQ append [%d]", thread.get_ident()) self.__addremovesem.acquire() if not self.__objects.has_key(item.id): self.__objects[item.id] = item if pys: item.addToSpace(self.__space) elif item in self.__toremove: self.__toremove.remove(item) else: self.__toadd.append(item) if isinstance(item, Planet) and not item in self.__planets and item.pull > 0: self.__planets.append(item) elif isinstance(item, Nebula) and not item in self.__nebulas and item.pull > 0: self.__nebulas.append(item) self.__addremovesem.release() logging.debug("SEMAPHORE REL append [%d]", thread.get_ident())
def service_thread(conn, addr): (caddr, cport) = addr print "Thread %s has connection from %s.\n" % (str(thread.get_ident()), caddr), stdin = conn.makefile("r") stdout = conn.makefile("w", 0) run_interpreter(stdin, stdout) print "Thread %s is done.\n" % str(thread.get_ident()),
def write(self, value): if thread.get_ident() != self.MAIN_THREAD: # put all children threads stdouts into a separate storage if thread.get_ident() not in self.thread_specific_outputs: self.thread_specific_outputs[thread.get_ident()] = value else: self.thread_specific_outputs[thread.get_ident()] += value else: # print all main thread stdouts the normal way sys.__stdout__.write(value)
def lookup(key): """Return the value of `key` in the current state""" try: state, getRule, lookup, child = states[get_ident()] except KeyError: empty().swap() state, getRule, lookup, child = states[get_ident()] return lookup(key)
def get(self, *args, **params): if not self.dict.has_key(_thread.get_ident()): if self.default is not None: self.put(self.default) elif self.creator is not None: self.put(self.creator(*args, **params)) return self.dict[_thread.get_ident()]
def main(): event = threading.Event() counter = [] print thread.get_ident() print thread.start_new_thread( thread_func, (event, counter) ) while len(counter) < end_count: event.set() time.sleep(2)
def run_thread(): for i in range(10): time.sleep(0.1) dprint("thread %s %d" % (thread.get_ident(), i)) mstr = String("thread %s %d" % (thread.get_ident(), i)) pstr = mstr.ToString() done.append(None) dprint("thread %s %d done" % (thread.get_ident(), i))
def GetActivityIds(self): if len(self.activities) == 0: self.RetrieveActivities() if len(self.activities) == 0: self.logger.error("[{i}] [{t}] [{f}] ({m})".format(i=self.id, t=thread.get_ident(), f=str(sys._getframe().f_code.co_name), m="No activities for this account")) raise NikePlusError("There are no activities for this account") self.logger.debug("[{i}] [{t}] [{f}] ({m})".format(i=self.id, t=thread.get_ident(), f=str(sys._getframe().f_code.co_name), m=str(self.activities.keys()))) return self.activities.keys()
def serve(environ, start_response): start_response("200 OK", [("Content-type", "text/plain")]) sess = create_session() l = sess.query(Foo).select() threadids.add(thread.get_ident()) print ("sending response on thread", thread.get_ident(), " total threads ", len(threadids)) return [str("\n".join([x.data for x in l]))]
def acquire(self): "If this thread does not own the cache, acquire the lock" if thread.get_ident() != self.owner_thread: # log('acquire: ident=%s' % thread.get_ident()) # XXX debug self.lock.acquire() self.owner_thread = thread.get_ident() # log('%s got lock' % thread.get_ident()) # XXX debug self.nref += 1
def _get_instance(): # get the current thread instance = INSTANCES.get(thread.get_ident()) if instance == None: # create a new container instance = Container() INSTANCES[thread.get_ident()] = instance return instance
def get(key=None): try: state, getRule, lookup, child = states[get_ident()] except KeyError: empty().swap() state, getRule, lookup, child = states[get_ident()] if key is None: return state return getRule(key)
def getresultqueue(self): """Return the thread specific result Queue object They are automatically allocated on demand""" q=self.resultqueues.get(thread.get_ident(), None) if q is not None: return q q=Queue.Queue() self.resultqueues[thread.get_ident()]=q return q
def _clear_request(self): try: del self._request_dict[_thread.get_ident()] except KeyError: pass
def get_request(self): return self._request_dict.get(_thread.get_ident())
def onpy_srcs(unit, *args): """ @usage PY_SRCS({| CYTHON_C} { | TOP_LEVEL | NAMESPACE ns} Files...) PY_SRCS() - is rule to build extended versions of Python interpreters and containing all application code in its executable file. It can be used to collect only the executables but not shared libraries, and, in particular, not to collect the modules that are imported using import directive. The main disadvantage is the lack of IDE support; There is also no readline yet. The application can be collect from any of the sources from which the C library, and with the help of PY_SRCS .py , .pyx,.proto and .swg files. At the same time extensions for Python on C language generating from .pyx and .swg, will be registered in Python's as built-in modules, and sources on .py are stored as static data: when the interpreter starts, the initialization code will add a custom loader of these modules to sys.meta_path. By default .pyx files are collected as C++-extensions. To collect them as C (similar to BUILDWITH_CYTHON_C, but with the ability to specify namespace), you must specify the Directive CYTHON_C. Building with pyx automatically registers modules, you do not need to call PY_REGISTER for them __init__.py never required, but if present (and specified in PY_SRCS), it will be imported when you import package modules with __init__.py Oh. Example of library declaration with PY_SRCS(): PY_LIBRARY(mymodule) PY_SRCS(a.py sub/dir/b.py e.proto sub/dir/f.proto c.pyx sub/dir/d.pyx g.swg sub/dir/h.swg) END() PY_REGISTER honors Python2 and Python3 differences and adjusts itself to Python version of a current module Documentation: https://wiki.yandex-team.ru/arcadia/python/pysrcs/#modulipylibrarypy3libraryimakrospysrcs """ # Each file arg must either be a path, or "${...}/buildpath=modname", where # "${...}/buildpath" part will be used as a file source in a future macro, # and "modname" will be used as a module name. upath = unit.path()[3:] py3 = is_py3(unit) with_py = not unit.get('PYBUILD_NO_PY') with_pyc = not unit.get('PYBUILD_NO_PYC') if not upath.startswith('contrib/tools/python') and not upath.startswith( 'library/python/runtime') and unit.get('NO_PYTHON_INCLS') != 'yes': unit.onpeerdir(['contrib/libs/python']) unit_needs_main = unit.get('MODULE_TYPE') in ('PROGRAM', 'DLL') if unit_needs_main: py_program(unit, py3) py_namespace_value = unit.get('PY_NAMESPACE_VALUE') if py_namespace_value == ".": ns = "" else: ns = (unit.get('PY_NAMESPACE_VALUE') or upath.replace('/', '.')) + '.' cython_coverage = unit.get('CYTHON_COVERAGE') == 'yes' cythonize_py = False optimize_proto = unit.get('OPTIMIZE_PY_PROTOS_FLAG') == 'yes' cython_directives = [] if cython_coverage: cython_directives += ['-X', 'linetrace=True'] pyxs_c = [] pyxs_c_h = [] pyxs_c_api_h = [] pyxs_cpp = [] pyxs = pyxs_cpp swigs_c = [] swigs_cpp = [] swigs = swigs_cpp pys = [] protos = [] evs = [] dump_dir = unit.get('PYTHON_BUILD_DUMP_DIR') dump_output = None if dump_dir: import thread pid = os.getpid() tid = thread.get_ident() dump_name = '{}-{}.dump'.format(pid, tid) dump_output = open(os.path.join(dump_dir, dump_name), 'a') args = iter(args) for arg in args: # Namespace directives. if arg == 'TOP_LEVEL': ns = '' elif arg == 'NAMESPACE': ns = next(args) + '.' # Cython directives. elif arg == 'CYTHON_C': pyxs = pyxs_c elif arg == 'CYTHON_C_H': pyxs = pyxs_c_h elif arg == 'CYTHON_C_API_H': pyxs = pyxs_c_api_h elif arg == 'CYTHON_CPP': pyxs = pyxs_cpp elif arg == 'CYTHON_DIRECTIVE': cython_directives += ['-X', next(args)] elif arg == 'CYTHONIZE_PY': cythonize_py = True # SWIG. elif arg == 'SWIG_C': swigs = swigs_c elif arg == 'SWIG_CPP': swigs = swigs_cpp # Unsupported but legal PROTO_LIBRARY arguments. elif arg == 'GLOBAL' or arg.endswith('.gztproto'): pass # Sources. else: main_mod = arg == 'MAIN' if main_mod: arg = next(args) if '=' in arg: main_py = False path, mod = arg.split('=', 1) else: path = arg main_py = (path == '__main__.py' or path.endswith('/__main__.py')) if not py3 and unit_needs_main and main_py: mod = '__main__' else: if arg.startswith('../'): ymake.report_configure_error( 'PY_SRCS item starts with "../": {!r}'.format(arg)) if arg.startswith('/'): ymake.report_configure_error( 'PY_SRCS item starts with "/": {!r}'.format(arg)) continue mod = ns + stripext(arg).replace('/', '.') if py3 and mod == '__main__': ymake.report_configure_error( 'TOP_LEVEL __main__.py is not allowed in PY3_PROGRAM') if main_mod: py_main(unit, mod + ":main") elif py3 and unit_needs_main and main_py: py_main(unit, mod) pathmod = (path, mod) if dump_output is not None: dump_output.write('{path}\t{module}\n'.format( path=rootrel_arc_src(path, unit), module=mod)) if path.endswith('.py'): if cythonize_py: pyxs.append(pathmod) else: pys.append(pathmod) elif path.endswith('.pyx'): pyxs.append(pathmod) elif path.endswith('.proto'): protos.append(pathmod) elif path.endswith('.ev'): evs.append(pathmod) elif path.endswith('.swg'): swigs.append(pathmod) else: ymake.report_configure_error( 'in PY_SRCS: unrecognized arg {!r}'.format(path)) if dump_output is not None: dump_output.close() if pyxs: files2res = set() # Include map stores files which were included in the processing pyx file, # to be able to find source code of the included file inside generated file # for currently processing pyx file. include_map = collections.defaultdict(set) if cython_coverage: def process_pyx(filename, path, out_suffix, noext): # skip generated files if not is_arc_src(path, unit): return # source file files2res.add((filename, path)) # generated if noext: files2res.add((os.path.splitext(filename)[0] + out_suffix, os.path.splitext(path)[0] + out_suffix)) else: files2res.add((filename + out_suffix, path + out_suffix)) # used includes for entry in parse_pyx_includes(filename, path, unit.resolve('$S')): files2res.add(entry) include_arc_rel = entry[0] include_map[filename].add(include_arc_rel) else: def process_pyx(filename, path, out_suffix, noext): pass for pyxs, cython, out_suffix, noext in [ (pyxs_c, unit.on_buildwith_cython_c_dep, ".c", False), (pyxs_c_h, unit.on_buildwith_cython_c_h, ".c", True), (pyxs_c_api_h, unit.on_buildwith_cython_c_api_h, ".c", True), (pyxs_cpp, unit.on_buildwith_cython_cpp_dep, ".cpp", False), ]: for path, mod in pyxs: filename = rootrel_arc_src(path, unit) cython_args = [path] dep = path if path.endswith('.py'): pxd = '/'.join(mod.split('.')) + '.pxd' if unit.resolve_arc_path(pxd): dep = pxd cython_args.append(dep) cython_args += [ '--module-name', mod, '--init-suffix', mangle(mod), '--source-root', '${ARCADIA_ROOT}', # set arcadia root relative __file__ for generated modules '-X', 'set_initial_path={}'.format(filename), ] + cython_directives cython(cython_args) py_register(unit, mod, py3) process_pyx(filename, path, out_suffix, noext) if files2res: # Compile original and generated sources into target for proper cython coverage calculation unit.onresource_files( [x for name, path in files2res for x in ('DEST', name, path)]) if include_map: data = [] prefix = 'resfs/cython/include' for line in sorted('{}/{}={}'.format(prefix, filename, ':'.join( sorted(files))) for filename, files in include_map.iteritems()): data += ['-', line] unit.onresource(data) for swigs, on_swig_python in [ (swigs_c, unit.on_swig_python_c), (swigs_cpp, unit.on_swig_python_cpp), ]: for path, mod in swigs: # Make output prefix basename match swig module name. prefix = path[:path.rfind('/') + 1] + mod.rsplit('.', 1)[-1] swg_py = '{}/{}/{}.py'.format('${ARCADIA_BUILD_ROOT}', upath, prefix) on_swig_python([path, prefix]) onpy_register(unit, mod + '_swg') onpy_srcs(unit, swg_py + '=' + mod) if pys: pys_seen = set() pys_dups = {m for _, m in pys if (m in pys_seen or pys_seen.add(m))} if pys_dups: ymake.report_configure_error( 'Duplicate(s) is found in the PY_SRCS macro: {}'.format( pys_dups)) res = [] if py3: for path, mod in pys: dest = 'py/' + mod.replace('.', '/') + '.py' if with_py: res += ['DEST', dest, path] if with_pyc: root_rel_path = rootrel_arc_src(path, unit) dst = path + uniq_suffix(path, unit) unit.on_py3_compile_bytecode( [root_rel_path + '-', path, dst]) res += ['DEST', dest + '.yapyc3', dst + '.yapyc3'] unit.onresource_files(res) add_python_lint_checks( unit, 3, [path for path, mod in pys] + unit.get(['_PY_EXTRA_LINT_FILES_VALUE']).split()) else: for path, mod in pys: root_rel_path = rootrel_arc_src(path, unit) if with_py: key = '/py_modules/' + mod res += [ path, key, '-', 'resfs/src/{}={}'.format(key, root_rel_path), ] if with_pyc: src = unit.resolve_arc_path(path) or path dst = path + uniq_suffix(path, unit) unit.on_py_compile_bytecode( [root_rel_path + '-', src, dst]) res += [dst + '.yapyc', '/py_code/' + mod] unit.onresource(res) add_python_lint_checks( unit, 2, [path for path, mod in pys] + unit.get(['_PY_EXTRA_LINT_FILES_VALUE']).split()) if protos: if not upath.startswith('contrib/libs/protobuf/python/google_lib'): unit.onpeerdir(['contrib/libs/protobuf/python/google_lib']) unit.onpeerdir(unit.get("PY_PROTO_DEPS").split()) proto_paths = [path for path, mod in protos] unit.on_generate_py_protos_internal(proto_paths) unit.onpy_srcs([ pb2_arg(py_suf, path, mod, unit) for path, mod in protos for py_suf in unit.get("PY_PROTO_SUFFIXES").split() ]) if optimize_proto: unit.onsrcs(proto_paths) pb_cc_outs = [ pb_cc_arg(cc_suf, path, unit) for path in proto_paths for cc_suf in unit.get("CPP_PROTO_SUFFIXES").split() ] for pb_cc_outs_chunk in generate_chunks(pb_cc_outs, 10): if unit_needs_main: unit.onjoin_srcs( ['join_' + listid(pb_cc_outs_chunk) + '.cpp'] + pb_cc_outs_chunk) else: unit.onjoin_srcs_global( ['join_' + listid(pb_cc_outs_chunk) + '.cpp'] + pb_cc_outs_chunk) if evs: if not upath.startswith('contrib/libs/protobuf/python/google_lib'): unit.onpeerdir(['contrib/libs/protobuf/python/google_lib']) unit.on_generate_py_evs_internal([path for path, mod in evs]) unit.onpy_srcs([ev_arg(path, mod, unit) for path, mod in evs]) if optimize_proto: unit.onsrcs([path for path, mod in evs]) pb_cc_outs = [ev_cc_arg(path, unit) for path, _ in evs] for pb_cc_outs_chunk in generate_chunks(pb_cc_outs, 10): if unit_needs_main: unit.onjoin_srcs( ['join_' + listid(pb_cc_outs_chunk) + '.cpp'] + pb_cc_outs_chunk) else: unit.onjoin_srcs_global( ['join_' + listid(pb_cc_outs_chunk) + '.cpp'] + pb_cc_outs_chunk)
def callback(): idents.append(thread.get_ident())
def unregisterThread(self): del self.__dict__['servers'][thread.get_ident()]
def logPrefix(self): self.logThreadID = get_ident() return 'Listener'
def occurred(self): self.success = True self.eventThreadID = get_ident() self._finished.callback(None)
def mpng(prefix, first=0, last=0, preserve=0, modal=0, mode=-1, quiet=1, width=0, height=0, _self=cmd): ''' DESCRIPTION "mpng" writes movie frames as a series of numbered png files. USAGE mpng prefix [, first [, last [, preserve [, modal [, mode [, quiet [, width [, height ]]]]]]]] ARGUMENTS prefix = string: filename prefix for saved images -- output files will be numbered and end in ".png" first = integer: starting frame {default: 0 (first frame)} last = integer: last frame {default: 0 (last frame)} preserve = 0/1: Only write non-existing files {default: 0} modal = integer: will frames be rendered with a modal draw loop mode = int: 2=ray, 1=draw, 0=normal {default: -1, check ray_trace_frames or draw_frames} width = int: width in pixels {default: current viewport} height = int: height in pixels {default: current viewport} NOTES If the "ray_trace_frames" variable is non-zero, then the frames will be ray-traced. Note that this can take many hours for a long movie with complex content displayed. Also, be sure to avoid setting "cache_frames" when rendering a long movie to avoid running out of memory. Arguments "first" and "last" can be used to specify an inclusive interval over which to render frames. Thus, you can write a smart Python program that will automatically distribute rendering over a cluster of workstations. If these options are left at zero, then the entire movie will be rendered. PYMOL API cmd.mpng(string prefix, int first, int last) SEE ALSO png, save ''' r = DEFAULT_ERROR args = (prefix, int(first) - 1, int(last) - 1, int(preserve), int(modal), -1, int(mode), int(quiet), int(width), int(height)) if thread.get_ident() == pymol.glutThread: r = _self._mpng(*args) else: r = _self.do('cmd._mpng(*%s, _self=cmd)' % repr(args), 0) if _self._raising(r, _self): raise pymol.CmdException return r
def __enter__(self): self.current = get_ident() pass
def thread_get_ident(self): return get_ident()
return self.b # --DEPARTURE-- # With this line, strings of length 1 or 2 don't go through the # stemming process, although no mention is made of this in the # published algorithm. Remove the line to match the published # algorithm. self.step1ab() self.step1c() self.step2() self.step3() self.step4() self.step5() return self.b[self.k0:self.k + 1] _stemmers[get_ident()] = PorterStemmer() def is_stemmer_available_for_language(lang): """Return true if stemmer for language LANG is available. Return false otherwise. """ return lang == 'en' def stem(word, lang): """Return WORD stemmed according to language LANG (e.g. 'en').""" if lang == 'en' and _stemmers and _stemmers.has_key(get_ident()): #make sure _stemmers[get_ident()] is avail.. return _stemmers[get_ident()].stem(word, 0, len(word) - 1) elif lang == 'el': #TODO: first we have to capitalize the word # and remove accents from the vowels
def currentGoal(self): return self._goals[thread.get_ident()]
def acquireconnection(self): """Fetches a connection from the pool, making sure to create a new one if needed, to obey the maximum connection limits, etc. Opens a connection to the server and returns an appropriate object.""" self.semaphore.acquire() self.connectionlock.acquire() imapobj = None if len(self.availableconnections): # One is available. # Try to find one that previously belonged to this thread # as an optimization. Start from the back since that's where # they're popped on. threadid = thread.get_ident() imapobj = None for i in range(len(self.availableconnections) - 1, -1, -1): tryobj = self.availableconnections[i] if self.lastowner[tryobj] == threadid: imapobj = tryobj del (self.availableconnections[i]) break if not imapobj: imapobj = self.availableconnections[0] del (self.availableconnections[0]) self.assignedconnections.append(imapobj) self.lastowner[imapobj] = thread.get_ident() self.connectionlock.release() return imapobj self.connectionlock.release() # Release until need to modify data """ Must be careful here that if we fail we should bail out gracefully and release locks / threads so that the next attempt can try... """ success = 0 try: while not success: # Generate a new connection. if self.tunnel: UIBase.getglobalui().connecting('tunnel', self.tunnel) imapobj = UsefulIMAP4_Tunnel(self.tunnel) success = 1 elif self.usessl: UIBase.getglobalui().connecting(self.hostname, self.port) imapobj = UsefulIMAP4_SSL(self.hostname, self.port, self.sslclientkey, self.sslclientcert) else: UIBase.getglobalui().connecting(self.hostname, self.port) imapobj = UsefulIMAP4(self.hostname, self.port) imapobj.mustquote = imaplibutil.mustquote if not self.tunnel: try: # Try GSSAPI and continue if it fails if 'AUTH=GSSAPI' in imapobj.capabilities and have_gss: UIBase.getglobalui().debug( 'imap', 'Attempting GSSAPI authentication') try: imapobj.authenticate('GSSAPI', self.gssauth) except imapobj.error, val: self.gssapi = False UIBase.getglobalui().debug( 'imap', 'GSSAPI Authentication failed') else: self.gssapi = True #if we do self.password = None then the next attempt cannot try... #self.password = None if not self.gssapi: if 'AUTH=CRAM-MD5' in imapobj.capabilities: UIBase.getglobalui().debug( 'imap', 'Attempting CRAM-MD5 authentication') try: imapobj.authenticate( 'CRAM-MD5', self.md5handler) except imapobj.error, val: self.plainauth(imapobj) else: self.plainauth(imapobj) # Would bail by here if there was a failure. success = 1 self.goodpassword = self.password except imapobj.error, val: self.passworderror = str(val) raise
def flush(self): if thread.get_ident() == self.socket_thread_id: self._write(''.join(self.writebuf)) self.writebuf = []
def connectionLost(self, reason): self.connLostThreadID = get_ident() self._finished.errback(reason)
def get_or_make_ident(): if we_are_translated(): return tlfield_thread_ident.get_or_make_raw() else: import thread return thread.get_ident()
def _set_request(self, request): self._request_dict[_thread.get_ident()] = request
USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.9/howto/static-files/ STATIC_URL = '/static/' log_dir = "/home/nemo/data/dz_logs/" log_dir = os.path.exists(log_dir) and log_dir or (os.popen("pwd").read().strip() + "/") uclite_log_filename = log_dir + "uclite_p%d_t%d.log" % (os.getpid(), thread.get_ident()) LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'standard': { 'format': 'tm=%(asctime)s`%(message)s`' }, }, 'handlers': { 'default': { 'level': 'INFO', 'class': 'logging.FileHandler', 'filename': uclite_log_filename,
def self(self): """This function bypasses the getattr and setattr trickery and returns the actual server object.""" return self.__dict__['servers'][thread.get_ident()]
def registerThread(self, server): self.__dict__['servers'][thread.get_ident()] = server
def start(my): print "starting thread: ", thread.get_ident() thread.start_new_thread(Queue._start, ("Queue", 1))
def stemWords(words, lang): """Return WORDS stemmed according to language LANG (e.g. 'en').""" if lang and is_stemmer_available_for_language(lang): return _stemmers[get_ident()][lang].stemWords(words) else: return words
def _locked_method(self, func, *args, **kwargs): if self._ident.current != get_ident(): with nested(*self.machine_context): return func(*args, **kwargs) else: return func(*args, **kwargs)
def get_global(cls, key): return cls._globals.get(thread.get_ident(), {}).get(key)
def _check_tid_after_load(self, oid_int, actual_tid_int, expect_tid_int=None): """Verify the tid of an object loaded from the database is sane.""" if actual_tid_int > self.current_tid: # Strangely, the database just gave us data from a future # transaction. We can't give the data to ZODB because that # would be a consistency violation. However, the cause is hard # to track down, so issue a ReadConflictError and hope that # the application retries successfully. raise ReadConflictError( "Got data for OID 0x%(oid_int)x from " "future transaction %(actual_tid_int)d (%(got_ts)s). " "Current transaction is %(current_tid)d (%(current_ts)s)." % { 'oid_int': oid_int, 'actual_tid_int': actual_tid_int, 'current_tid': self.current_tid, 'got_ts': str(TimeStamp(p64(actual_tid_int))), 'current_ts': str(TimeStamp(p64(self.current_tid))), }) if expect_tid_int is not None and actual_tid_int != expect_tid_int: # Uh-oh, the cache is inconsistent with the database. # Possible causes: # # - The database MUST provide a snapshot view for each # session; this error can occur if that requirement is # violated. For example, MySQL's MyISAM engine is not # sufficient for the object_state table because MyISAM # can not provide a snapshot view. (InnoDB is # sufficient.) # # - Something could be writing to the database out # of order, such as a version of RelStorage that # acquires a different commit lock. # # - A software bug. In the past, there was a subtle bug # in after_poll() that caused it to ignore the # transaction order, leading it to sometimes put the # wrong tid in delta_after*. cp0, cp1 = self.checkpoints import os import thread raise AssertionError( "Detected an inconsistency " "between the RelStorage cache and the database " "while loading an object using the delta_after0 dict. " "Please verify the database is configured for " "ACID compliance and that all clients are using " "the same commit lock. " "(oid_int=%(oid_int)r, expect_tid_int=%(expect_tid_int)r, " "actual_tid_int=%(actual_tid_int)r, " "current_tid=%(current_tid)r, cp0=%(cp0)r, cp1=%(cp1)r, " "len(delta_after0)=%(lda0)r, len(delta_after1)=%(lda1)r, " "pid=%(pid)r, thread_ident=%(thread_ident)r)" % { 'oid_int': oid_int, 'expect_tid_int': expect_tid_int, 'actual_tid_int': actual_tid_int, 'current_tid': self.current_tid, 'cp0': cp0, 'cp1': cp1, 'lda0': len(self.delta_after0), 'lda1': len(self.delta_after1), 'pid': os.getpid(), 'thread_ident': thread.get_ident(), })
def set_global(cls, key, value): ident = thread.get_ident() if ident not in cls._globals: cls._globals[ident] = {} cls._globals[ident][key] = value
def onpy_srcs(unit, *args): """ PY_SRCS() - is rule to build extended versions of Python interpreters and containing all application code in its executable file. It can be used to collect only the executables but not shared libraries, and, in particular, not to collect the modules that are imported using import directive. The main disadvantage is the lack of IDE support; There is also no readline yet. The application can be collect from any of the sources from which the C library, and with the help of PY_SRCS .py , .pyx,.proto and .swg files. At the same time extensions for Python on C language generating from .pyx and .swg, will be registered in Python's as built-in modules, and sources on .py are stored as static data: when the interpreter starts, the initialization code will add a custom loader of these modules to sys.meta_path. By default .pyx files are collected as C++-extensions. To collect them as C (similar to BUILDWITH_CYTHON_C, but with the ability to specify namespace), you must specify the Directive CYTHON_C. Building with pyx automatically registers modules, you do not need to call PY_REGISTER for them __init__.py never required, but if present (and specified in PY_SRCS), it will be imported when you import package modules with __init__.py Oh. Example of library declaration with PY_SRCS(): PY_LIBRARY(mymodule) PY_SRCS({| CYTHON_C} { | TOP_LEVEL | NAMESPACE ns} a.py sub/dir/b.py e.proto sub/dir/f.proto c.pyx sub/dir/d.pyx g.swg sub/dir/h.swg) END() Documentation: https://wiki.yandex-team.ru/devtools/commandsandvars/py_srcs/ """ # Each file arg must either be a path, or "${...}/buildpath=modname", where # "${...}/buildpath" part will be used as a file source in a future macro, # and "modname" will be used as a module name. py3 = is_py3(unit) if py3: if '/contrib/tools/python3/src/Lib' not in unit.path(): unit.onpeerdir(['contrib/libs/python']) if '/library/python/runtime_py3' not in unit.path(): unit.onpeerdir(['library/python/runtime_py3']) else: if '/contrib/tools/python/src/Lib' not in unit.path(): unit.onpeerdir(['contrib/libs/python']) if '/library/python/runtime' not in unit.path(): unit.onpeerdir(['library/python/runtime']) is_program = unit.get('MODULE_TYPE') == 'PROGRAM' if is_program: py_program(unit, py3) py_namespace_value = unit.get('PY_NAMESPACE_VALUE') if py_namespace_value == ".": ns = "" else: ns = (unit.get('PY_NAMESPACE_VALUE') or unit.path()[3:].replace('/', '.')) + '.' cython_coverage = unit.get('CYTHON_COVERAGE') == 'yes' optimize_proto = unit.get('OPTIMIZE_PY_PROTOS_FLAG') == 'yes' cython_includes = [] for path in unit.includes(): cython_includes += ['-I', resolve_to_ymake_path(path)] cython_directives = [] if cython_coverage: cython_directives += ['-X', 'linetrace=True'] pyxs_c = [] pyxs_cpp = [] pyxs = pyxs_cpp pys = [] protos = [] evs = [] swigs = [] dump_dir = unit.get('PYTHON_BUILD_DUMP_DIR') dump_output = None if dump_dir: import thread pid = os.getpid() tid = thread.get_ident() dump_name = '{}-{}.dump'.format(pid, tid) dump_output = open(os.path.join(dump_dir, dump_name), 'a') args = iter(args) for arg in args: # Namespace directives. if arg == 'TOP_LEVEL': ns = '' elif arg == 'NAMESPACE': ns = next(args) + '.' # Cython directives. elif arg == 'CYTHON_C': pyxs = pyxs_c elif arg == 'CYTHON_CPP': pyxs = pyxs_cpp elif arg == 'CYTHON_DIRECTIVE': cython_directives += ['-X', next(args)] # Unsupported but legal PROTO_LIBRARY arguments. elif arg == 'GLOBAL' or arg.endswith('.gztproto'): pass # Sources. else: main_mod = arg == 'MAIN' if main_mod: arg = next(args) if '=' in arg: main_py = False path, mod = arg.split('=', 1) else: path = arg main_py = (path == '__main__.py' or path.endswith('/__main__.py')) if not py3 and main_py: mod = '__main__' else: if arg.startswith('../'): ymake.report_configure_error('PY_SRCS item starts with "../": {!r}'.format(arg)) if arg.startswith('/'): ymake.report_configure_error('PY_SRCS item starts with "/": {!r}'.format(arg)) continue mod = ns + stripext(arg).replace('/', '.') if py3 and mod == '__main__': ymake.report_configure_error('TOP_LEVEL __main__.py is not allowed in PY3_PROGRAM') if main_mod: py_main(unit, mod + ":main") elif py3 and main_py: py_main(unit, mod) pathmod = (path, mod) if dump_output is not None: dump_output.write('{path}\t{module}\n'.format(path=rootrel_arc_src(path, unit), module=mod)) if path.endswith('.py'): pys.append(pathmod) elif path.endswith('.pyx'): pyxs.append(pathmod) elif path.endswith('.proto'): protos.append(pathmod) elif path.endswith('.ev'): evs.append(pathmod) elif path.endswith('.swg'): if py3: ymake.report_configure_error('SWIG is not yet supported for Python 3: https://st.yandex-team.ru/DEVTOOLS-4863') else: swigs.append(path) # ignore mod, use last (and only) ns else: ymake.report_configure_error('in PY_SRCS: unrecognized arg {!r}'.format(path)) if dump_output is not None: dump_output.close() if pyxs: files2res = set() if cython_coverage: def process_pyx(filename, path, out_suffix): # skip generated files if not is_arc_src(path, unit): return # source file files2res.add((filename, path)) # generated files2res.add((filename + out_suffix, path + out_suffix)) # used includes for entry in parse_pyx_includes(filename, path, unit.resolve('$S')): files2res.add(entry) else: def process_pyx(filename, path, out_suffix): pass for pyxs, cython, out_suffix in [ (pyxs_c, unit.onbuildwith_cython_c, ".c"), (pyxs_cpp, unit.onbuildwith_cython_cpp, ".cpp"), ]: for path, mod in pyxs: filename = rootrel_arc_src(path, unit) cython([ path, '--module-name', mod, '--init-suffix', mangle(mod), '--source-root', '${ARCADIA_ROOT}', # set arcadia root relative __file__ for generated modules '-X', 'set_initial_path={}'.format(filename), ] + cython_includes + cython_directives) py_register(unit, mod, py3) process_pyx(filename, path, out_suffix) if files2res: # Compile original and generated sources into target for proper cython coverage calculation unit.onresource_files([x for name, path in files2res for x in ('DEST', name, path)]) if pys: pys_seen = set() pys_dups = {m for _, m in pys if (m in pys_seen or pys_seen.add(m))} if pys_dups: ymake.report_configure_error('Duplicate(s) is found in the PY_SRCS macro: {}'.format(pys_dups)) res = [] if py3: for path, mod in pys: root_rel_path = rootrel_arc_src(path, unit) unit.onpy3_compile_bytecode([root_rel_path + '-', path]) dest = 'py/' + mod.replace('.', '/') + '.py' res += [ 'DEST', dest, path, 'DEST', dest + '.yapyc3', path + '.yapyc3' ] unit.onresource_files(res) #add_python_lint_checks(unit, [path for path, mod in pys]) else: for path, mod in pys: root_rel_path = rootrel_arc_src(path, unit) src = unit.resolve_arc_path(path) or path dst = tobuilddir(src) + '.yapyc' unit.onpy_compile_bytecode([root_rel_path + '-', src]) key = '/py_modules/' + mod res += [ path, key, '-', 'resfs/src/{}={}'.format(key, root_rel_path), dst, '/py_code/' + mod, ] unit.onresource(res) add_python_lint_checks(unit, [path for path, mod in pys]) if protos: if '/contrib/libs/protobuf/python/google_lib' not in unit.path(): unit.onpeerdir(['contrib/libs/protobuf/python/google_lib']) grpc = unit.get('GRPC_FLAG') == 'yes' if grpc: unit.onpeerdir(['contrib/libs/grpc/python', 'contrib/libs/grpc']) proto_paths = [path for path, mod in protos] unit.ongenerate_py_protos(proto_paths) unit.onpy_srcs([pb2_arg(path, mod, unit) for path, mod in protos]) if grpc: unit.onpy_srcs([pb2_grpc_arg(path, mod, unit) for path, mod in protos]) if optimize_proto: unit.onsrcs(proto_paths) pb_cc_outs = [pb_cc_arg(path, unit) for path in proto_paths] if grpc: pb_cc_outs += [pb_grpc_arg(path, unit) for path in proto_paths] for pb_cc_outs_chunk in generate_chunks(pb_cc_outs, 10): if is_program: unit.onjoin_srcs(['join_' + listid(pb_cc_outs_chunk) + '.cpp'] + pb_cc_outs_chunk) else: unit.onjoin_srcs_global(['join_' + listid(pb_cc_outs_chunk) + '.cpp'] + pb_cc_outs_chunk) if unit.get('GLYCINE_FLAG') == 'yes': unit.onpeerdir(['glycine/gen/runtime']) unit.ongenerate_py_glys(proto_paths) unit.onpy_srcs([gly_arg(path, mod, unit) for path, mod in protos]) if evs: if '/contrib/libs/protobuf/python/google_lib' not in unit.path(): unit.onpeerdir(['contrib/libs/protobuf/python/google_lib']) unit.ongenerate_py_evs([path for path, mod in evs]) unit.onpy_srcs([ev_arg(path, mod, unit) for path, mod in evs]) if optimize_proto: unit.onsrcs([path for path, mod in evs]) pb_cc_outs = [ev_cc_arg(path, unit) for path, _ in evs] for pb_cc_outs_chunk in generate_chunks(pb_cc_outs, 10): if is_program: unit.onjoin_srcs(['join_' + listid(pb_cc_outs_chunk) + '.cpp'] + pb_cc_outs_chunk) else: unit.onjoin_srcs_global(['join_' + listid(pb_cc_outs_chunk) + '.cpp'] + pb_cc_outs_chunk) if swigs: unit.onsrcs(swigs) prefix = unit.get('MODULE_PREFIX') project = unit.get('REALPRJNAME') py_register(unit, prefix + project, py3) path = '${ARCADIA_BUILD_ROOT}/' + '{}/{}.py'.format(unit.path()[3:], project) arg = '{}={}'.format(path, ns + project.replace('/', '.')) unit.onpy_srcs([arg])
from IPython import ultraTB, ipapi from IPython.genutils import Term,warn,error,flag_calls, ask_yes_no from IPython.iplib import InteractiveShell from IPython.ipmaker import make_IPython from IPython.Magic import Magic from IPython.ipstruct import Struct # Globals # global flag to pass around information about Ctrl-C without exceptions KBINT = False # global flag to turn on/off Tk support. USE_TK = False # ID for the main thread, used for cross-thread exceptions MAIN_THREAD_ID = thread.get_ident() # Tag when runcode() is active, for exception handling CODE_RUN = None #----------------------------------------------------------------------------- # This class is trivial now, but I want to have it in to publish a clean # interface. Later when the internals are reorganized, code that uses this # shouldn't have to change. class IPShell: """Create an IPython instance.""" def __init__(self,argv=None,user_ns=None,user_global_ns=None, debug=1,shell_class=InteractiveShell): self.IP = make_IPython(argv,user_ns=user_ns,
#self.password = None if self.delim == None: listres = imapobj.list(self.reference, '""')[1] if listres == [None] or listres == None: # Some buggy IMAP servers do not respond well to LIST "" "" # Work around them. listres = imapobj.list(self.reference, '"*"')[1] self.delim, self.root = \ imaputil.imapsplit(listres[0])[1:] self.delim = imaputil.dequote(self.delim) self.root = imaputil.dequote(self.root) self.connectionlock.acquire() self.assignedconnections.append(imapobj) self.lastowner[imapobj] = thread.get_ident() self.connectionlock.release() return imapobj except: """If we are here then we did not succeed in getting a connection - we should clean up and then re-raise the error...""" self.semaphore.release() #Make sure that this can be retried the next time... self.passworderror = None if (self.connectionlock.locked()): self.connectionlock.release() raise def connectionwait(self): """Waits until there is a connection available. Note that between
def _formatOutput( self, level, args, tag = "" ): # # Try to get context information. Looking for the name of the file we # are in, the name of the function (with possible class name # prepended), and if we are formatting a Begin() call, a list of # argnames and values that describe what is being passed into the # function we are logging. # doBegin = tag == self.kEntryTag and len( args ) == 0 file, proc, bArgs = self._procInfo( doBegin ) if len( bArgs ) > 0: args = bArgs # # Use arrays to build up message string in place. Should be faster than # string manipulations. # s = array.array( 'c' ) # # Generate timestamp # if self.showTime: now = time.time() now = time.strftime( "%Y%m%d.%H%M%S", time.localtime( now ) ) s.fromstring( now ) s.append( ' ' ) # # Generate thread ID # if self.showThread: from thread import get_ident s.append( '#' ) s.fromstring( str( get_ident() ) ) s.append( ' ' ) # # Print file name containing the log statement # if self.showFile: s.fromstring( file ) s.append( ' ' ) # # Print the function name containing the log statement. May also have a # class name if this is a method. # if self.showFunc: s.fromstring( proc ) s.append( ' ' ) # # Print BEG/END tag # if len( tag ) > 0: s.fromstring( tag ) s.append( ' ' ) # # Append each argument to message string # for each in args: if type( each ) is _kTypeString: s.fromstring( each ) else: s.fromstring( repr( each ) ) s.append( ' ' ) # # Finally, append a newline # s.append( '\n' ) # # Return string representation of array # return s.tostring()