• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python thread.allocate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中thread.allocate函数的典型用法代码示例。如果您正苦于以下问题:Python allocate函数的具体用法?Python allocate怎么用?Python allocate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: __init__

 def __init__(self):
     self.Receipt = {}
     self._lock = thread.allocate()
     self._evtMailGot = threading.Event()
     self._eventSerial = 0
     self._timeOut = 15
     self._timeLimit = 0
     self._ready = False
开发者ID:Cosimzhou,项目名称:py-truffle,代码行数:8,代码来源:multithread.py


示例2: __init__

    def __init__(self, func, func_args=(), encoding='gbk', failed_delay=2, max_retry=10):
        self.encoding = encoding        
        self.lock = thread.allocate()
        self.failed_delay = failed_delay
        self.max_retry = max_retry
        self.finished = False
        self.retry_times = 0
        self.worker_func = func
        self.func_args = func_args
        self.thread = threading.Thread(target=self._func)

        super(SingleThread, self).__init__()
开发者ID:enix223,项目名称:estock,代码行数:12,代码来源:single_thread.py


示例3: loop2

def loop2():
    print "loop2程序开始 ",ctime()
    locks = []
    nloops = range(len(loops))
    for i in nloops:  #用于批量创建锁对象
        lock = thread.allocate() #创建锁对象
        lock.acquire() #尝试获取锁对象
        locks.append(lock)
    for i in nloops:
        thread.start_new_thread(loop,(i,loops[i],locks[i]))
    sleep(4)
    print "---all done---"
开发者ID:asd359,项目名称:hello-word,代码行数:12,代码来源:thread.py


示例4: initialize

def initialize():
    """Setup the Kinect hardware and register callbacks"""
    global screen_lock, screen, kinect
    screen_lock = thread.allocate()

    kinect = KinectRuntime()

    kinect.depth_frame_ready += depth_frame_ready
    # kinect.video_frame_ready += video_frame_ready

    # kinect.video_stream.open(nui.ImageStreamType.Video, 2,
    # nui.ImageResolution.Resolution640x480, nui.ImageType.Color)
    kinect.depth_stream.open(nui.ImageStreamType.Depth, 2, nui.ImageResolution.Resolution640x480, nui.ImageType.Depth)
开发者ID:rmccue,项目名称:depthmapper,代码行数:13,代码来源:kinect.py


示例5: search

def search(domains, results):
    now = datetime.now()
    lock = thread.allocate()
    sys.stdout.write('Date: %s' %now.strftime('%Y-%m-%d %H:%M:%S\n\n'))
    for domain in domains:
        if domain in results:
            continue

        thread.start_new(can_taken_via_whois, (domain, lock))

        #can_taken_via_whois(domain, lock)
        time.sleep(0.5)
    sys.stdout.write('\n')
    sys.stdout.flush()
开发者ID:alswl,项目名称:domain_search,代码行数:14,代码来源:domain_search.py


示例6: test_start_new_thread

def test_start_new_thread():
    #--Sanity
    global CALLED
    CALLED = False
    
    lock = thread.allocate()    
    def tempFunc(mykw_param=1):
        global CALLED
        lock.acquire()
        CALLED = mykw_param
        lock.release()
        thread.exit_thread()
        
    id = thread.start_new_thread(tempFunc, (), {"mykw_param":7})
    while CALLED==False:
        print ".",
        time.sleep(1)
    AreEqual(CALLED, 7)
    
    id = thread.start_new_thread(tempFunc, (), {"mykw_param":8})
    while CALLED!=8:  #Hang forever if this is broken
        print ".",
        time.sleep(1)
    
    #--Sanity Negative
    global temp_stderr
    temp_stderr = ""
    se = sys.stderr
    
    class myStdOut:
        def write(self, text): 
            global temp_stderr
            temp_stderr += text

    try:
        sys.stderr = myStdOut()
        
        id = thread.start_new_thread(tempFunc, (), {"my_misspelled_kw_param":9})
        time.sleep(5)
        if not is_silverlight:
            se.flush()
    finally:
        sys.stderr = se
    
    AreEqual(CALLED, 8)
    Assert("tempFunc() got an unexpected keyword argument 'my_misspelled_kw_param" in temp_stderr)
开发者ID:mdavid,项目名称:dlr,代码行数:46,代码来源:thread_test.py


示例7: __init__

	def __init__(self):
		self.mutex = thread.allocate()
		self.todo = thread.allocate()
		self.todo.acquire()
		self.work = []
		self.busy = 0
开发者ID:asottile,项目名称:ancient-pythons,代码行数:6,代码来源:find.py


示例8: len

        
        if len(histl)>3:
            histr=histr[len(histr)-3:len(histr):1]
            histl=histl[len(histl)-3:len(histl):1]



if __name__ == '__main__':
        import libardrone
        drn=libardrone.ARDrone()

        full_screen = False
        draw_skeleton = True
        video_display = False

        screen_lock = thread.allocate()
        screen = pygame.display.set_mode(DEPTH_WINSIZE,0,16)    
        pygame.display.set_caption('Mirror Ver.K')
        Flight_mode=False
        Malayalam_mode=True

        skeletons = None
        #screen.fill(THECOLORS["black"])
        kinect = nui.Runtime()
        kinect.skeleton_engine.enabled = True
        
 
        def post_frame(frame):
            try:
                   pygame.event.post(pygame.event.Event(KINECTEVENT, skeletons = frame.SkeletonData))
            except:
开发者ID:Ajmalfiroz,项目名称:MagnetoDrone,代码行数:30,代码来源:Test.py


示例9: __init__

 def __init__(self):
     super(ChangeTimeWidget, self).__init__()
     proxy = dbus.SystemBus().get_object("org.gnome.SettingsDaemon.DateTimeMechanism", "/")
     self.dbus_iface = dbus.Interface(proxy, dbus_interface="org.gnome.SettingsDaemon.DateTimeMechanism")
     
     # Ensures we're setting the system time only when the user changes it
     self.changedOnTimeout = False
     
     # Ensures we don't update the values in the date/time fields during the DBus call to set the time
     self._setting_time = False
     self._setting_time_lock = thread.allocate()
     self._time_to_set = None
     
     self.thirtyDays = [3, 5, 8, 10]
     months = ['January','February','March','April','May','June','July','August','September','October','November','December']
     
     # Boxes
     timeBox = Gtk.HBox()
     dateBox = Gtk.HBox()
     
     # Combo Boxes
     self.monthBox = Gtk.ComboBoxText()
     
     for month in months:
         self.monthBox.append_text(month)
     
     # Adjustments
     hourAdj = Gtk.Adjustment(0, 0, 23, 1, 1)
     minAdj = Gtk.Adjustment(0, 0, 59, 1, 1)
     yearAdj = Gtk.Adjustment(0, 0, 9999, 1, 5)
     dayAdj = Gtk.Adjustment(0, 1, 31, 1, 1)
     
     # Spin buttons
     self.hourSpin = Gtk.SpinButton()
     self.minSpin = Gtk.SpinButton()
     self.yearSpin = Gtk.SpinButton()
     self.daySpin = Gtk.SpinButton()
     
     self.hourSpin.configure(hourAdj, 0.5, 0)
     self.minSpin.configure(minAdj, 0.5, 0)
     self.yearSpin.configure(yearAdj, 0.5, 0)
     self.daySpin.configure(dayAdj, 0.5, 0)
     self.hourSpin.set_editable(False)
     self.minSpin.set_editable(False)
     self.yearSpin.set_editable(False)
     self.daySpin.set_editable(False)
     
     self.update_time()
     GObject.timeout_add(1000, self.update_time)
     
     # Connect to callback
     self.hourSpin.connect('changed', self._change_system_time)
     self.minSpin.connect('changed', self._change_system_time)
     self.monthBox.connect('changed', self._change_system_time)
     self.yearSpin.connect('changed', self._change_system_time)
     self.daySpin.connect('changed', self._change_system_time)
     
     timeBox.pack_start(self.hourSpin, False, False, 2)
     timeBox.pack_start(Gtk.Label(_(":")), False, False, 2)
     timeBox.pack_start(self.minSpin, False, False, 2)
     
     dateBox.pack_start(self.monthBox, False, False, 2)
     dateBox.pack_start(self.daySpin, False, False, 2)
     dateBox.pack_start(self.yearSpin, False, False, 2)
     
     self.pack_start(Gtk.Label(_("Date : ")), False, False, 2)
     self.pack_start(dateBox, True, True, 2)
     self.pack_start(Gtk.Label(_("Time : ")), False, False, 2)
     self.pack_start(timeBox, True, True, 2)
开发者ID:chamfay,项目名称:Cinnamon,代码行数:69,代码来源:cinnamon-settings.py


示例10: start_thread

import thread
import time

lock=thread.allocate()

def start_thread(func, params):
  lock.acquire()
  thread.start_new_thread(thread_wrapper, (func, params))

def thread_wrapper(func, params):
  lock.release()
  apply(func, params)

def mythread(id):
  print 'id = %d'%id
  time.sleep(1)

for i in range(100):
  start_thread(mythread, (i,))

print 'Success!'
开发者ID:pombreda,项目名称:comp304,代码行数:21,代码来源:testthread.py


示例11: runa

# -*- coding: cp936 -*-
'''
author:郎芭
QQ:149737748
'''
import os,urllib2,time,sys,re
import thread
from bs4 import BeautifulSoup
start_time=time.clock()
za='<div.*</div>'
a=thread.allocate()#多线程用的锁
a.acquire()  #设置第二部份锁为阻塞
b=thread.allocate()
b.acquire()#第三部分
c=thread.allocate()
c.acquire()#第四部分
d=thread.allocate()
d.acquire()


def runa(qi,zhi,wurl,x,y):
    result=''
    soup=bsp(wurl)
    lzname=soup.find('div',{'class':'atl-menu clearfix js-bbs-act'})['js_activityusername']
    for i in xrange(int(qi),int(zhi)+1):
        newurl='http://bbs.tianya.cn/post-%s-%s-%s.shtml'%(x,y,i)
        txt=pagecollect(newurl,lzname)
        if txt:print u'The page %s  is completed!\r'%i,
        else:  print u'The page %s  is None!     \r'%i,
        result +=txt
    #优先写入第一部分内容,再解锁第二部分阻塞!    
开发者ID:netldds,项目名称:little,代码行数:31,代码来源:TianyaDL_4thread_bs4.py


示例12: process


#.........这里部分代码省略.........
            draw_skeleton_data(data, index, RIGHT_ARM)
            draw_skeleton_data(data, index, LEFT_LEG)
            draw_skeleton_data(data, index, RIGHT_LEG)


    def depth_frame_ready(frame):
        if video_display:
            return

        with screen_lock:
            address = surface_to_array(screen)
            frame.image.copy_bits(address)
            del address
            if skeletons is not None and draw_skeleton:
                draw_skeletons(skeletons)
            pygame.display.update()    


    def video_frame_ready(frame):
        if not video_display:
            return

        with screen_lock:
            address = surface_to_array(screen)
            frame.image.copy_bits(address)
            del address
            if skeletons is not None and draw_skeleton:
                draw_skeletons(skeletons)
            pygame.display.update()


    full_screen = False
    draw_skeleton = True
    video_display = False

    screen_lock = thread.allocate()

    screen = pygame.display.set_mode(DEPTH_WINSIZE,0,16)    
    pygame.display.set_caption('Python Kinect Demo')
    skeletons = None
    screen.fill(THECOLORS["black"])

    kinect = nui.Runtime()
    kinect.skeleton_engine.enabled = True
    def post_frame(frame):
        try:
            pygame.event.post(pygame.event.Event(KINECTEVENT, skeletons = frame.SkeletonData))
        except:
            # event queue full
            pass

    kinect.skeleton_frame_ready += post_frame
    
    kinect.depth_frame_ready += depth_frame_ready    
    kinect.video_frame_ready += video_frame_ready    
    
    kinect.video_stream.open(nui.ImageStreamType.Video, 2, nui.ImageResolution.Resolution640x480, nui.ImageType.Color)
    kinect.depth_stream.open(nui.ImageStreamType.Depth, 2, nui.ImageResolution.Resolution320x240, nui.ImageType.Depth)

    print('Controls: ')
    print('     d - Switch to depth view')
    print('     v - Switch to video view')
    print('     s - Toggle displaing of the skeleton')
    print('     u - Increase elevation angle')
    print('     j - Decrease elevation angle')

    # main game loop
    done = False

    while not done:
        e = pygame.event.wait()
        dispInfo = pygame.display.Info()
        if e.type == pygame.QUIT:
            done = True
            break
        elif e.type == KINECTEVENT:
            skeletons = e.skeletons
            if draw_skeleton:
                draw_skeletons(skeletons)
                pygame.display.update()
        elif e.type == KEYDOWN:
            if e.key == K_ESCAPE:
                done = True
                break
            elif e.key == K_d:
                with screen_lock:
                    screen = pygame.display.set_mode(DEPTH_WINSIZE,0,16)
                    video_display = False
            elif e.key == K_v:
                with screen_lock:
                    screen = pygame.display.set_mode(VIDEO_WINSIZE,0,32)    
                    video_display = True
            elif e.key == K_s:
                draw_skeleton = not draw_skeleton
            elif e.key == K_u:
                kinect.camera.elevation_angle = kinect.camera.elevation_angle + 2
            elif e.key == K_j:
                kinect.camera.elevation_angle = kinect.camera.elevation_angle - 2
            elif e.key == K_x:
                kinect.camera.elevation_angle = 2
开发者ID:CameronParker,项目名称:kinect-2-snap,代码行数:101,代码来源:pygame_multiprocessing_test.py


示例13: __init__

    def __init__(self):
        self.width = 640
        self.height = 480
        pygame.time.set_timer(TIMER_EVENT, 25)
        self.screen_lock = thread.allocate()
        self.last_kinect_event = time.clock()
        self.screen = pygame.display.set_mode((self.width, self.height), 
                                              0, 32)

        self.dispInfo = pygame.display.Info()
        self.screen.convert()
        pygame.display.set_caption('Python Kinect Game')
        self.screen.fill(THECOLORS["black"])
    
        self.background = pygame.Surface((self.width, self.height), 0, 32)
        self.background.fill(THECOLORS["black"])
        self.background.convert()

        self.video_screen = pygame.SurfaceType((self.width, self.height),
                                               0,
                                               32)    

        self.ball_group = sprite.Group(
            Ball(self, 'white', direction = math.atan2(.5, 1), 
                 x = 30, y = 410), 
            Ball(self, 'white', direction = math.atan2(0, -1), 
                 x = 600, y = 400),
            Ball(self, 'white', direction = math.atan2(0, -1), 
                 x = 30, y = 240),
            Ball(self, 'white', direction = math.atan2(1, -1.1), 
                 x = 10, y = 140),
        )
        self.known_players = {}

        self.score_font = pygame.font.SysFont('Segoe UI', 20, bold=True)

        self.pieces_group = sprite.Group()
        
        self.left_margin = (self.width / 5)
        self.top_margin = (self.height / 5)
        self.blocks_across = 10
        self.blocks_down = 10
        width = ((self.width - self.left_margin) / self.blocks_across) - 5
        height = ((self.height - self.top_margin) / self.blocks_down) - 5
        for y in xrange(self.blocks_down):
            for x in xrange(self.blocks_across):
                if x not in (3, 4, 5, 6) or not y in (4, 5):
                    x_loc = ((self.width - self.left_margin) / 
                             self.blocks_across) * x + (self.left_margin / 2)
                    y_loc = ((self.height - self.top_margin) / 
                             self.blocks_down) * y + (self.top_margin / 2)

                    bp = BoardPiece(x_loc, y_loc, width, height)
                    bp.add(self.pieces_group)

        self.bumper_group = sprite.Group()

        self.kinect = nui.Runtime()
        self.kinect.skeleton_engine.enabled = True
        self.kinect.skeleton_frame_ready += post_frame
        self.kinect.video_frame_ready += self.video_frame_ready    
        self.kinect.video_stream.open(nui.ImageStreamType.Video, 2, 
                                      nui.ImageResolution.Resolution640x480, 
                                      nui.ImageType.Color)
开发者ID:Michael0x2a,项目名称:kinect-guerilla-art,代码行数:64,代码来源:Game.py


示例14: send_http

             {"drawPhone": "13798580366", "drawUserId": "488984"},
             {"drawPhone": "13510212603", "drawUserId": "488984"},
             {"drawPhone": "18912352222", "drawUserId": "488984"},
             {"drawPhone": "18912351111", "drawUserId": "488984"},
             {"drawPhone": "18912348888", "drawUserId": "488984"},
             {"drawPhone": "18912347777", "drawUserId": "488984"},
             {"drawPhone": "18912346666", "drawUserId": "488984"},
             {"drawPhone": "18912345555", "drawUserId": "488984"},
             {"drawPhone": "18912344444", "drawUserId": "488984"}
             ]

# 字段说明,必须一一对应
# login为空表示使用随机用户名

now_count = 0
lock_obj = thread.allocate()


def send_http():
    global now_count
    try:
        index = random.randint(0, (len(user_list) - 1))
        user = user_list[index]
        url = 'http://' + addr + ':' + str(
            port) + restful + '?token=' + token + '&' + params + '&drawPhone=' + user.get(
            'drawPhone') + '&drawUserId=' + user.get('drawUserId')
        response = requests.get(url)

        #print '发送数据: ' + url
        #print '返回码: ' + str(response.status_code)
        #print '返回数据: ' + response.content
开发者ID:IRH01,项目名称:snake,代码行数:31,代码来源:stress_draw_test.py


示例15: __init__

 def __init__(self, *args, **kwdargs):
     self.lock = thread.allocate()
     return super(ThreadSafeWriter, self).__init__(*args, **kwdargs)
开发者ID:FiaDot,项目名称:programmer-competency-matrix,代码行数:3,代码来源:selenium_test1.py


示例16:

# A parallelized "find(1)" using the thread module.
开发者ID:mcyril,项目名称:ravel-ftn,代码行数:1,代码来源:find.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python thread.allocate_lock函数代码示例发布时间:2022-05-27
下一篇:
Python thread._get_ident函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap