小编Kyl*_*ble的帖子

扭曲的逻辑错误

我的扭曲程序有效,但现在我的一个反应堆没有优先考虑其他反应堆.我希望controlListener reactor执行一次迭代,然后将优先级传递给printstuffs reactor.

 #Random class as proof of concept
 class printStuffs(object):  
         print "counting "
         printerCount = 0
         def count(self):
             self.printerCount = self.printerCount + 1
             print ("the counter is at " + str(self.printerCount))

  ##########################################################################
  ## The control listneer class is designed to kill given reactor threads ##
  ## on demand from something once it recieves a signal it is supposed    ##
  ## to do one ieteration then release                                    ##
  ##########################################################################

  class controlListener(object):
          counter = 20
          def count(self):
               if self.counter == 0: …
Run Code Online (Sandbox Code Playgroud)

python logic twisted

9
推荐指数
1
解决办法
256
查看次数

tweepy如何从id获取用户名

如何使用tweepy从用户ID编号中删除明文用户名?

这是我正在使用的CORRECTED代码:

ids = []
userid = "someOne"
for page in tweepy.Cursor(api.followers_ids, screen_name=userid).pages():
     ids.extend(page)
     time.sleep(60)

print len(ids), "following have been gathered from", userid  

users = api.lookup_users(user_ids=ids)#ieterates through the list of users and prints them
for u in users:
    print u.screen_name
Run Code Online (Sandbox Code Playgroud)

我评论的最后一行是给我一个问题的那一行.请指教.谢谢你们!

python tweepy

7
推荐指数
1
解决办法
4327
查看次数

python TypeError:未绑定的方法错误

我之前从未见过这个错误:

TypeError: unbound method halt_listener() must be called with test_imports instance as first argument (got Queue instance instead)

我在运行此代码时得到它:

class test_imports:#Test classes remove 
      alive = {'import_1': True, 'import_2': True};

      def halt_listener(self, control_Queue, thread_Name, kill_command):
          while True:
              print ("Checking queue for kill")
              isAlive = control_queue.get()
              print ("isAlive", isAlive)
              if isAlive == kill_command:
                 print ("kill listener triggered")
                 self.alive[thread_Name] = False;
                 return

      def import_1(self, control_Queue, thread_Number):
          print ("Import_1 number %d started") % thread_Number
          t = Thread(target=test_imports.halt_listener, args=(control_Queue, 'import_1', 't1kill'))
          count = 0 
          t.run() …
Run Code Online (Sandbox Code Playgroud)

python multithreading typeerror

1
推荐指数
1
解决办法
3259
查看次数

Python线程执行阻塞其他线程

两个线程在访问时都有效,但是当它们一起执行时halt_listener将独占不允许import_1执行的资源.最终目标是让halt_listener侦听kill消息,然后将run变量设置为false.当我向halt_listener发送管道时,这有用,但我更喜欢队列.

这是我的代码:

import multiprocessing 
import time 
from threading import Thread

class test_imports:#Test classes remove 
      alive = {'import_1': True, 'import_2': True};

      def halt_listener(self, control_Queue, thread_Name, kill_command):
          while True:
              print ("Checking queue for kill")
              isAlive = control_queue.get()
              print ("isAlive", isAlive)
              if isAlive == kill_command:
                 print ("kill listener triggered")
                 self.alive[thread_Name] = False;
                 return

      def import_1(self, control_Queue, thread_Number):
          print ("Import_1 number %d started") % thread_Number
          halt = test_imports()
          t = Thread(target=halt.halt_listener, args=(control_Queue, 'import_1', 't1kill'))
          count = 0 
          t.run()
          global alive …
Run Code Online (Sandbox Code Playgroud)

python multithreading execution

1
推荐指数
1
解决办法
1274
查看次数

为什么我的诅咒盒子不会画出来?

我正在玩诅咒,我无法在屏幕上画一个盒子.我创建了一个有效的边框,但我想在边框中绘制一个框

这是我的代码

import curses 

screen = curses.initscr()

try:
    screen.border(0)
    box1 = curses.newwin(20, 20, 5, 5)
    box1.box()
    screen.getch()

finally:
    curses.endwin()
Run Code Online (Sandbox Code Playgroud)

任何建议?

python curses draw

1
推荐指数
2
解决办法
1万
查看次数

在tweepy中循环错误

我最近一直在玩弄tweepy,我试图吸引追随者并跟随给定用户.

 followingids = []
 followids = []
 userid = "Someone"#sets target

 for page in tweepy.Cursor(api.followers_ids, screen_name=userid).pages():#gets the followers for userID
     followingids.extend(page)
     time.sleep(60)#keeps us cool with twitter


  for page in tweepy.Cursor(api.friends_ids, screen_name=userid).pages():#gets the followers for userID
     followids.extend(page)
     time.sleep(60)#keeps us cool with twitter

 #where weirdness starts 
 print len(followingids), "followers have been gathered from", userid 
 print len(followids), " users are followed by ", userid

 followingusers = api.lookup_users(user_ids=followingids)#ieterates through the list of users and prints them
 followedusers = api.lookup_users(user_ids=followids) #<does not work but above …
Run Code Online (Sandbox Code Playgroud)

printing for-loop tweepy

1
推荐指数
1
解决办法
834
查看次数