当前位置: 首页>>代码示例>>Python>>正文


Python Random.atfork方法代码示例

本文整理汇总了Python中Crypto.Random.atfork方法的典型用法代码示例。如果您正苦于以下问题:Python Random.atfork方法的具体用法?Python Random.atfork怎么用?Python Random.atfork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypto.Random的用法示例。


在下文中一共展示了Random.atfork方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __getitem__

# 需要导入模块: from Crypto import Random [as 别名]
# 或者: from Crypto.Random import atfork [as 别名]
def __getitem__(self, item):
        if self.first_run:
            Random.atfork()
            self.first_run = False

        content = [random.randrange(0, len(self.chars)) for _ in range(self.n_chars)]

        s = ''.join([self.chars[i] for i in content])

        d = self.gen.generate(s)
        d = Image.open(d)

        label = torch.full((self.n_chars + 2, ), self.tokenizer.EOS_token, dtype=torch.long)

        ts = self.tokenizer.tokenize(s)
        label[:ts.shape[0]] = torch.tensor(ts)

        return img_trans(d), label 
开发者ID:wptoux,项目名称:attention-ocr,代码行数:20,代码来源:dataset.py

示例2: gen_key

# 需要导入模块: from Crypto import Random [as 别名]
# 或者: from Crypto.Random import atfork [as 别名]
def gen_key():
    '''
    Generates a new label or shared key.
    '''

    rpool =  Random.new()
    Random.atfork() 
    return rpool.read(16).encode("hex") 
开发者ID:sophron,项目名称:BAR,代码行数:10,代码来源:pybar.py

示例3: gen_lbl

# 需要导入模块: from Crypto import Random [as 别名]
# 或者: from Crypto.Random import atfork [as 别名]
def gen_lbl():
    '''
    Generate a new Label.
    '''

    rpool =  Random.new()
    Random.atfork() 
    return rpool.read(16).encode("hex") 
开发者ID:sophron,项目名称:BAR,代码行数:10,代码来源:label.py

示例4: post_fork

# 需要导入模块: from Crypto import Random [as 别名]
# 或者: from Crypto.Random import atfork [as 别名]
def post_fork(server, worker):
    # Reset the Random library to ensure it won't raise the "PID check failed." error after
    # gunicorn forks.
    Random.atfork() 
开发者ID:quay,项目名称:quay,代码行数:6,代码来源:gunicorn_local.py

示例5: wrap_message

# 需要导入模块: from Crypto import Random [as 别名]
# 或者: from Crypto.Random import atfork [as 别名]
def wrap_message(msg):
    Random.atfork()
    aes_key = randfile.read(32)
    aes_obj = AES.new(aes_key, AES.MODE_CBC, "0" * 16)
    enc_msg = aes_obj.encrypt(msg)
    aes_key_int = int.from_bytes(aes_key, byteorder="little")
    c0, c1 = elgamal_enc(pub_key, aes_key_int)

    blob = c0.x.to_bytes(35, byteorder="little", signed=False) \
           + c0.y.to_bytes(35, byteorder="little", signed=False) \
           + c1.to_bytes(42, byteorder="little", signed=False) \
           + enc_msg
    return blob 
开发者ID:vvv214,项目名称:LDP_Protocols,代码行数:15,代码来源:ec_crypto.py

示例6: enc_all

# 需要导入模块: from Crypto import Random [as 别名]
# 或者: from Crypto.Random import atfork [as 别名]
def enc_all(msg, num_layer):
    Random.atfork()
    blob = wrap_message(msg)
    for _ in range(num_layer - 1):
        new_blob = wrap_message(blob)
        blob = new_blob
    return blob 
开发者ID:vvv214,项目名称:LDP_Protocols,代码行数:9,代码来源:ec_crypto.py

示例7: atfork

# 需要导入模块: from Crypto import Random [as 别名]
# 或者: from Crypto.Random import atfork [as 别名]
def atfork(self):
        """
        Terminate this Transport without closing the session.  On posix
        systems, if a Transport is open during process forking, both parent
        and child will share the underlying socket, but only one process can
        use the connection (without corrupting the session).  Use this method
        to clean up a Transport object without disrupting the other process.

        @since: 1.5.3
        """
        self.sock.close()
        self.close() 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:14,代码来源:transport.py

示例8: _init_db

# 需要导入模块: from Crypto import Random [as 别名]
# 或者: from Crypto.Random import atfork [as 别名]
def _init_db(self):
        """We need this to be executed each time we are in a new process"""
        if self._autoreindex:
            subscribers.init()

        Random.atfork()

        self.__conn_refs = {}
        self.__thread_local = threading.local()
        self.__thread_watcher = ThreadWatcher()
        self._storage = client_storage(**self.__storage_kwargs)
        self._db = SubDB(self._storage, **self.__db_kwargs)
        self._conn_open() 
开发者ID:zerodb,项目名称:zerodb,代码行数:15,代码来源:db.py

示例9: start_client

# 需要导入模块: from Crypto import Random [as 别名]
# 或者: from Crypto.Random import atfork [as 别名]
def start_client(self, event=None):
        """
        Negotiate a new SSH2 session as a client.  This is the first step after
        creating a new L{Transport}.  A separate thread is created for protocol
        negotiation.

        If an event is passed in, this method returns immediately.  When
        negotiation is done (successful or not), the given C{Event} will
        be triggered.  On failure, L{is_active} will return C{False}.

        (Since 1.4) If C{event} is C{None}, this method will not return until
        negotation is done.  On success, the method returns normally.
        Otherwise an SSHException is raised.

        After a successful negotiation, you will usually want to authenticate,
        calling L{auth_password <Transport.auth_password>} or
        L{auth_publickey <Transport.auth_publickey>}.

        @note: L{connect} is a simpler method for connecting as a client.

        @note: After calling this method (or L{start_server} or L{connect}),
            you should no longer directly read from or write to the original
            socket object.

        @param event: an event to trigger when negotiation is complete
            (optional)
        @type event: threading.Event

        @raise SSHException: if negotiation fails (and no C{event} was passed
            in)
        """
        self.active = True
        if event is not None:
            # async, return immediately and let the app poll for completion
            self.completion_event = event
            self.start()
            return

        # synchronous, wait for a result
        self.completion_event = event = threading.Event()
        self.start()
        Random.atfork()
        while True:
            event.wait(0.1)
            if not self.active:
                e = self.get_exception()
                if e is not None:
                    raise e
                raise SSHException('Negotiation failed.')
            if event.isSet():
                break 
开发者ID:iopsgroup,项目名称:imoocc,代码行数:53,代码来源:transport.py


注:本文中的Crypto.Random.atfork方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。