示例#1
0
 def test_vtk(self, request, tmp_path, ref_path, update,
              patch_execution_stamp, patch_datetime_now, output, fname,
              inc):
     result = Result(ref_path / fname).view('increments', inc)
     os.chdir(tmp_path)
     result.save_VTK(output)
     fname = fname.split(
         '.')[0] + f'_inc{(inc if type(inc) == int else inc[0]):0>2}.vtr'
     last = ''
     for i in range(10):
         if os.path.isfile(tmp_path / fname):
             with open(fname) as f:
                 cur = hashlib.md5(f.read().encode()).hexdigest()
                 if cur == last:
                     break
                 else:
                     last = cur
         time.sleep(.5)
     if update:
         with open((ref_path / 'save_VTK' /
                    request.node.name).with_suffix('.md5'), 'w') as f:
             f.write(cur)
     with open((ref_path / 'save_VTK' /
                request.node.name).with_suffix('.md5')) as f:
         assert cur == f.read()
示例#2
0
def start_container():
    global file_sock

    # TODO: if we can get rid of this, we can get rid of the ns module
    rv = ol.unshare()
    assert rv == 0

    # we open a new .sock file in the child, before starting the grand
    # child, which will actually use it.  This is so that the parent
    # can know that once the child exits, it is safe to start sending
    # messages to the sock file.
    file_sock = tornado.netutil.bind_unix_socket(file_sock_path)

    pid = os.fork()
    assert(pid >= 0)

    if pid > 0:
        # orhpan the new process by exiting parent.  The parent
        # process is in a weird state because unshare only partially
        # works for the process that calls it.
        os._exit(0)

    with open(bootstrap_path) as f:
        # this code can be whatever OL decides, but it will probably do the following:
        # 1. some imports
        # 2. call either web_server or fork_server
        code = f.read()
        try:
            exec(code)
        except Exception as e:
            print("Exception: " + traceback.format_exc())
            print("Problematic Python Code:\n" + code)
示例#3
0
 def test_vtk(self, request, tmp_path, ref_path, update,
              patch_execution_stamp, patch_datetime_now, output, fname,
              inc):
     result = Result(ref_path / fname).view(increments=inc)
     os.chdir(tmp_path)
     result.export_VTK(output, parallel=False)
     fname = fname.split(
         '.')[0] + f'_inc{(inc if type(inc) == int else inc[0]):0>2}.vti'
     v = VTK.load(tmp_path / fname)
     v.set_comments('n/a')
     v.save(tmp_path / fname, parallel=False)
     with open(fname) as f:
         cur = hashlib.md5(f.read().encode()).hexdigest()
     if update:
         with open((ref_path / 'export_VTK' /
                    request.node.name).with_suffix('.md5'), 'w') as f:
             f.write(cur + '\n')
     with open((ref_path / 'export_VTK' /
                request.node.name).with_suffix('.md5')) as f:
         assert cur == f.read().strip('\n')
示例#4
0
文件: server.py 项目: xuuuyp/FTP
def send_file(message, conn):
    global initial_address
    name = message.split()[1]  # 获取第二个参数(文件名)
    fileName = initial_address + '/' + name
    # fileName = r'./' + name
    with open(fileName, 'rb') as f:
        while True:
            a = f.read(1024)
            if not a:
                break
            conn.send(a)
    time.sleep(0.1)  # 延时确保文件发送完整
    conn.send('EOF'.encode())
示例#5
0
    words1 = sentence1.strip().split(" ")
    words2 = sentence2.split(" ")
    score = 0
    for word1 in words1:
        for word2 in words2:
            if word1.lower() == word2.lower():
                score += 1
    return score


if __name__ == '__main__':
    # print(wordsMastch("My name is Prabal Gupta", "Prabal is a good boy"))
    # sentences = ["My name is Prabal Gupta", "Prabal is a good boy", "this is python", "Python is very easy",
    #              "but not too much easy", "prabal is a python developer and Python developer are nice and good"]
    with open("prabal_e.txt") as f:
        fileData = f.read()
    with open("srijan_e.txt") as f:
        file2Data = f.read()
    sentences = [fileData, file2Data]
    search = input("Search here : ")
    import time
    startTime = time.time()
    scores = [wordsMastch(search, sentence) for sentence in sentences]
    # print(scores)
    sortedFinalScores = [
        sortedScore
        for sortedScore in sorted(zip(scores, sentences), reverse=True)
    ]
    finishTime = time.time()
    timeTaken = finishTime - startTime
    # print(sortedFinalScores)