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


Python Process.daemon方法代码示例

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


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

示例1: test_pause_unpause

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def test_pause_unpause(self):
        output = Queue.Queue()
        self.uri_opener.pause(True)

        def send(uri_opener, output):
            url = URL(get_moth_http())
            try:
                http_response = uri_opener.GET(url)
                output.put(http_response)
            except:
                output.put(None)

        th = Process(target=send, args=(self.uri_opener, output))
        th.daemon = True
        th.start()

        self.assertRaises(Queue.Empty, output.get, True, 2)

        self.uri_opener.pause(False)

        http_response = output.get()
        self.assertNotIsInstance(http_response, types.NoneType,
                                 'Error in send thread.')
        
        th.join()
        
        self.assertEqual(http_response.get_code(), 200)
        self.assertIn(self.MOTH_MESSAGE, http_response.body)
开发者ID:0x554simon,项目名称:w3af,代码行数:30,代码来源:test_xurllib.py

示例2: test_stop

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def test_stop(self):
        """
        Verify that the stop method actually works. In this case, working
        means that the process doesn't send any more HTTP requests after we
        stop().

        This test seems to be failing @ CircleCI because of a test dependency
        issue. If run alone in your workstation it will PASS, but if run at
        CircleCI the count plugin doesn't seem to start.
        """
        core_start = Process(target=self.w3afcore.start, name='TestRunner')
        core_start.daemon = True
        core_start.start()
        
        # Let the core start, and the count plugin send some requests.
        time.sleep(5)
        count_before_stop = self.count_plugin.count
        self.assertGreater(count_before_stop, 0)
        
        # Stop now,
        self.w3afcore.stop()
        core_start.join()

        count_after_stop = self.count_plugin.count
        
        self.assertEqual(count_after_stop, count_before_stop)
开发者ID:3rdDegree,项目名称:w3af,代码行数:28,代码来源:test_pause_stop.py

示例3: test_pause_unpause

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def test_pause_unpause(self):
        """
        Verify that the pause method actually works. In this case, working
        means that the process doesn't send any more HTTP requests, fact
        that is verified with the "fake" count plugin.
        """        
        core_start = Process(target=self.w3afcore.start, name='TestRunner')
        core_start.daemon = True
        core_start.start()
        
        # Let the core start, and the count plugin send some requests.
        time.sleep(5)
        count_before_pause = self.count_plugin.count
        self.assertGreater(self.count_plugin.count, 0)
        
        # Pause and measure
        self.w3afcore.pause(True)
        count_after_pause = self.count_plugin.count
        
        time.sleep(2)
        count_after_sleep = self.count_plugin.count
        
        all_equal = count_before_pause == count_after_pause == count_after_sleep
        
        self.assertTrue(all_equal)

        # Unpause and verify that all requests were sent
        self.w3afcore.pause(False)
        core_start.join()
        
        self.assertEqual(self.count_plugin.count, self.count_plugin.loops)
开发者ID:3rdDegree,项目名称:w3af,代码行数:33,代码来源:test_pause_stop.py

示例4: test_pause_stop

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def test_pause_stop(self):
        """
        Verify that the pause method actually works. In this case, working
        means that the process doesn't send any more HTTP requests after we,
        pause and that stop works when paused.
        """
        core_start = Process(target=self.w3afcore.start, name="TestRunner")
        core_start.daemon = True
        core_start.start()

        # Let the core start, and the count plugin send some requests.
        time.sleep(5)
        count_before_pause = self.count_plugin.count
        self.assertGreater(self.count_plugin.count, 0)

        # Pause and measure
        self.w3afcore.pause(True)
        count_after_pause = self.count_plugin.count

        time.sleep(2)
        count_after_sleep = self.count_plugin.count

        all_equal = count_before_pause == count_after_pause == count_after_sleep

        self.assertTrue(all_equal)

        # Unpause and verify that all requests were sent
        self.w3afcore.stop()
        core_start.join()

        # No more requests sent after pause
        self.assertEqual(self.count_plugin.count, count_after_sleep)
开发者ID:zhuyue1314,项目名称:w3af,代码行数:34,代码来源:test_pause_stop.py

示例5: process_request

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def process_request(self, request, client_address):
        """
        Start a new thread to process the request.

        Override here
        """
        t = Process(target=self.process_request_thread, args=(request, client_address))
        t.daemon = self.daemon_threads
        t.start()
开发者ID:ZionOps,项目名称:w3af,代码行数:11,代码来源:mp_flask.py

示例6: test_pause

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def test_pause(self):
        output = Queue.Queue()
        self.uri_opener.pause(True)

        def send(uri_opener, output):
            url = URL('http://moth/')
            http_response = uri_opener.GET(url)
            output.put(http_response)

        th = Process(target=send, args=(self.uri_opener, output))
        th.daemon = True
        th.start()

        self.assertRaises(Queue.Empty, output.get, True, 2)
开发者ID:Adastra-thw,项目名称:w3af,代码行数:16,代码来源:test_xurllib.py

示例7: scan_stop

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
def scan_stop(scan_id):
    """
    Stop a scan

    :param scan_id: The scan ID to stop
    :return: Empty result if success, 403 if the current state indicates that
             the scan can't be stopped.
    """
    scan_info = get_scan_info_from_id(scan_id)
    if scan_info is None:
        abort(404, 'Scan not found')

    if not scan_info.w3af_core.can_stop():
        abort(403, 'Scan can not be stop')

    t = Process(target=scan_info.w3af_core.stop, name='ScanStopThread', args=())
    t.daemon = True
    t.start()

    return jsonify({'message': 'Stopping scan'})
开发者ID:foobarmonk,项目名称:w3af,代码行数:22,代码来源:scans.py

示例8: test_pause_unpause

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def test_pause_unpause(self):
        output = Queue.Queue()
        self.uri_opener.pause(True)

        def send(uri_opener, output):
            url = URL('http://moth/')
            http_response = uri_opener.GET(url)
            output.put(http_response)

        th = Process(target=send, args=(self.uri_opener, output))
        th.daemon = True
        th.start()

        self.assertRaises(Queue.Empty, output.get, True, 2)

        self.uri_opener.pause(False)

        http_response = output.get()
        th.join()
        
        self.assertEqual(http_response.get_code(), 200)
        self.assertIn(self.MOTH_MESSAGE, http_response.body)
开发者ID:Adastra-thw,项目名称:w3af,代码行数:24,代码来源:test_xurllib.py

示例9: test_stop

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def test_stop(self):
        """
        Verify that the stop method actually works. In this case, working
        means that the process doesn't send any more HTTP requests after we
        stop().
        """
        core_start = Process(target=self.w3afcore.start, name="TestRunner")
        core_start.daemon = True
        core_start.start()

        # Let the core start, and the count plugin send some requests.
        time.sleep(5)
        count_before_stop = self.count_plugin.count
        self.assertGreater(count_before_stop, 0)

        # Stop now,
        self.w3afcore.stop()
        core_start.join()

        count_after_stop = self.count_plugin.count

        self.assertEqual(count_after_stop, count_before_stop)
开发者ID:zhuyue1314,项目名称:w3af,代码行数:24,代码来源:test_pause_stop.py

示例10: test_pause_stop

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def test_pause_stop(self):
        """
        Verify that the pause method actually works. In this case, working
        means that the process doesn't send any more HTTP requests after we,
        pause and that stop works when paused.

        This test seems to be failing @ CircleCI because of a test dependency
        issue. If run alone in your workstation it will PASS, but if run at
        CircleCI the count plugin doesn't seem to start.
        """
        core_start = Process(target=self.w3afcore.start, name='TestRunner')
        core_start.daemon = True
        core_start.start()
        
        # Let the core start, and the count plugin send some requests.
        time.sleep(5)
        count_before_pause = self.count_plugin.count
        self.assertGreater(self.count_plugin.count, 0)
        
        # Pause and measure
        self.w3afcore.pause(True)
        count_after_pause = self.count_plugin.count
        
        time.sleep(2)
        count_after_sleep = self.count_plugin.count
        
        all_equal = count_before_pause == count_after_pause == count_after_sleep
        
        self.assertTrue(all_equal)

        # Unpause and verify that all requests were sent
        self.w3afcore.stop()
        core_start.join()
        
        # No more requests sent after pause
        self.assertEqual(self.count_plugin.count, count_after_sleep)
开发者ID:3rdDegree,项目名称:w3af,代码行数:38,代码来源:test_pause_stop.py

示例11: abort

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
        abort(400, str(bfe))

    scan_id = get_new_scan_id()
    scan_info = ScanInfo()
    scan_info.w3af_core = w3af_core
    scan_info.target_urls = target_urls
    scan_info.profile_path = scan_profile_file_name
    scan_info.output = RESTAPIOutput()
    SCANS[scan_id] = scan_info

    #
    # Finally, start the scan in a different thread
    #
    args = (scan_info,)
    t = Process(target=start_scan_helper, name='ScanThread', args=args)
    t.daemon = True

    t.start()

    return jsonify({'message': 'Success',
                    'id': scan_id,
                    'href': '/scans/%s' % scan_id}), 201


@app.route('/scans/', methods=['GET'])
@requires_auth
def list_scans():
    """
    :return: A JSON containing a list of:
        - Scan resource URL (eg. /scans/1)
        - Scan target
开发者ID:foobarmonk,项目名称:w3af,代码行数:33,代码来源:scans.py

示例12: Value

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    ("../modelzoo/hand/test.prototxt", "../modelzoo/hand/vgg16_faster_rcnn_handGesdet_aug_fulldata_iter_50000.caffemodel", 0.4, 0.8, ('natural', 'yes', 'no')), (hand_inp_q, hand_res_q)))

    svm_reload_1 = Value('i', 0)
    worker_face_p1 = Process(target = modelPrepare, args = ('faceRecModel',
    ("../modelzoo/face/haarcascade_frontalface_alt.xml", "./align/shape_predictor_68_face_landmarks.dat", "../modelzoo/face/LightenedCNN_B_deploy.prototxt", "../modelzoo/face/LightenedCNN_B.caffemodel", "eltwise_fc1", "./profiles/svm_model.bin"), (face_inp_q, face_res_q, facemdl_continue_evt, svm_reload_1, "./profiles/svm_model.bin")))

    dummycontinue = True
    worker_handres_mailman = DummyProcess(target = resMailMan, args = (hand_res_q, 'hand_res'))
    worker_faceres_mailman = DummyProcess(target = resMailMan, args = (face_res_q, 'face_res'))
    worker_pref_writeman = DummyProcess(target = savePref, args = (pref_wrt_q, 'pref_wrt'))
    worker_svm_trainer = DummyProcess(target = updateFaceClassifier, args = (10,))

    #  worker_preprocess_p.daemon = True
    worker_hand_p1.daemon = True
    worker_face_p1.daemon = True
    worker_handres_mailman.daemon = True
    worker_faceres_mailman.daemon = True
    worker_pref_writeman.daemon = True
    worker_svm_trainer.daemon = True

    #  worker_preprocess_p.start()
    worker_hand_p1.start()
    worker_face_p1.start()
    worker_handres_mailman.start()
    worker_faceres_mailman.start()
    worker_pref_writeman.start()
    worker_svm_trainer.start()

    with open('./profiles/profiles.pkl', 'rb') as pref_fd:
        try:
            pref_db = pkl.load(pref_fd)
开发者ID:ZhengRui,项目名称:cardea-server,代码行数:33,代码来源:serv.py

示例13: start_scan

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
def start_scan():
    """
    Starts a new w3af scan

    Receive a JSON containing:
        - A list with the target URLs
        - The profile (eg. the content of fast_scan.pw3af)

    :return: A JSON containing:
        - The URL to the newly created scan (eg. /scans/1)
        - The newly created scan ID (eg. 1)
    """
    if not request.json or 'scan_profile' not in request.json:
        abort(400, 'Expected scan_profile in JSON object')

    if 'target_urls' not in request.json:
        abort(400, 'Expected target_urls in JSON object')

    scan_profile = request.json['scan_profile']
    target_urls = request.json['target_urls']

    #
    # First make sure that there are no other scans running, remember that this
    # REST API is an MVP and we can only run one scan at the time (for now)
    #
    scan_infos = SCANS.values()
    if not all([si is None for si in scan_infos]):
        abort(400, 'This version of the REST API does not support'
                   ' concurrent scans. Remember to DELETE finished scans'
                   ' before starting a new one.')

    #
    # Before trying to start a new scan we verify that the scan profile is
    # valid and return an informative error if it's not
    #
    # scan_profile_file_name, profile_path = create_temp_profile(scan_profile)
    # w3af_core = w3afCore()
    #
    # try:
    #     w3af_core.profiles.use_profile(scan_profile_file_name,
    #                                    workdir=profile_path)
    # except BaseFrameworkException, bfe:
    #     abort(400, str(bfe))

    #
    # Now that we know that the profile is valid I verify the scan target info
    #
    if not len(target_urls):
        abort(400, 'No target URLs specified')

    for target_url in target_urls:
        try:
            URL(target_url)
        except ValueError:
            abort(400, 'Invalid URL: "%s"' % target_url)

    # target_options = w3af_core.target.get_options()
    # target_option = target_options['target']
    # try:
    #     target_option.set_value([URL(u) for u in target_urls])
    #     w3af_core.target.set_options(target_options)
    # except BaseFrameworkException, bfe:
    #     abort(400, str(bfe))

    #
    # Finally, start the scan in a different thread
    #
    scan_id = get_new_scan_id()
    scan_info_setup = Event()

    args = (target_urls, scan_profile, scan_info_setup)
    t = Process(target=start_scan_helper, name='ScanThread', args=args)
    t.daemon = True

    t.start()

    # Wait until the thread starts
    scan_info_setup.wait()

    return jsonify({'message': 'Success',
                    'id': scan_id,
                    'href': '/scans/%s' % scan_id}), 201
开发者ID:batmanWjw,项目名称:w3af,代码行数:84,代码来源:scans.py

示例14: run

# 需要导入模块: from multiprocessing.dummy import Process [as 别名]
# 或者: from multiprocessing.dummy.Process import daemon [as 别名]
    def run(self, func=None, workhorse=True):

        if self.kwargs.get('socket'):
            try:
                from emross.utility.socket import establish_connection
                self.socket = establish_connection()

                socket_handler = JsonSocketHandler(self.socket, self.bots)
                socket_handler.daemon = True
                socket_handler.start()
            except Exception as e:
                logger.exception(e)


        self.initialise_bots(
            socket_writer=getattr(self.socket, 'queue_out', None),
            settings=self.settings
        )

        workers = []
        for bot in self.bots:
            bot.session.start_time = time.time()

            if func:
                logger.info('Starting new bot thread for {0}'.format(bot.api.player))
                worker = threading.Thread(target=func, args=(bot,))
                worker.bot = bot
                worker.daemon = True
                worker.start()
            else:
                logger.debug('No need to use a main thread for this worker!')
                worker = EmrossBaseObject(bot)

            workers.append(worker)


        """
        Now we can start the main event loop.
        If we are running a console then the `code.interact` will block
        so we need to spawn a thread to process each bot's error queue.
        """

        error_thread = Process(target=_error_checker, args=(workers, self.bots))
        error_thread.daemon = True
        error_thread.start()

        processes = self.kwargs.get('processes') or DEFAULT_POOL_SIZE

        queue = Queue.Queue(processes)
        for i in range(processes):
            t = Process(target=_bot_consumer, args=(queue,))
            t.daemon = True
            t.start()

        if self.console:
            worker = Process(target=_bot_runner, args=(queue, self.bots),
                                kwargs=self.kwargs)
            worker.daemon = True
            worker.start()

            import emross.utility.settings
            sandbox = dict(
                manager=self,
                settings=emross.utility.settings,
                bot=self.bot
            )
            code.interact(banner='EmrossWar Bot Management console', local=sandbox)
            raise KeyboardInterrupt
        elif workhorse:
            # We can run this directly in this thread
            _bot_runner(queue, self.bots, **self.kwargs)
开发者ID:cwild,项目名称:emrosswar-bot,代码行数:73,代码来源:manager.py


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