# use -l/--peer-logging option to enable peer logging
peer_logging = False
-# number of state_callback calls to print peer list information
+# print peer list information each PEERLIST_OUTPUT_INTERVAL seconds
PEERLIST_OUTPUT_INTERVAL = 5
-# number of callback counts
-callback_count = 0
-
# Print torrent statistics
def state_callback(ds):
d = ds.get_download()
if not peer_logging:
return (1.0, peer_logging)
- # peer listing each PEERLIST_OUTPUT_INTERVAL state_callback calls
- global callback_count
- callback_count = callback_count + 1
-
- if callback_count == PEERLIST_OUTPUT_INTERVAL:
- callback_count = 0
- peerlist = ds.get_peerlist()
+ # peer listing each PEERLIST_OUTPUT_INTERVAL seconds
+ seconds_since_epoch = int(time.time())
+ if seconds_since_epoch % PEERLIST_OUTPUT_INTERVAL == 0:
print >>sys.stderr, '--Peers: (%s) ' % (time.strftime("%b %d %H:%M:%S", time.localtime())),
+ peerlist = ds.get_peerlist()
if peerlist is None or not peerlist:
pass
else: