Esempio n. 1
0
 def source_thread_target(procs):
     for i in range(3):
         extend_stream(procs,
                       data=list(range(i * 2, (i + 1) * 2)),
                       stream_name='x')
         time.sleep(0.001)
     terminate_stream(procs, stream_name='x')
Esempio n. 2
0
 def thread_target_numpy(procs):
     for i in range(3):
         extend_stream(procs,
                       data=list(range(i * 10, (i + 1) * 10)),
                       stream_name='x')
         time.sleep(0.001)
     terminate_stream(procs, stream_name='x')
Esempio n. 3
0
 def source_thread_target(procs):
     data = list(range(10))
     extend_stream(procs,
                   data=list(range(10)),
                   stream_name='sound_made')
     time.sleep(0.0001)
     extend_stream(procs, data=[0] * 10, stream_name='sound_made')
     terminate_stream(procs, stream_name='sound_made')
Esempio n. 4
0
 def source_thread_target(procs):
     extend_stream(procs,
                   data=np.arange(10, dtype='float'),
                   stream_name='sound_made')
     time.sleep(0.0001)
     extend_stream(procs=procs,
                   data=np.zeros(10, dtype='float'),
                   stream_name='sound_made')
     terminate_stream(procs, stream_name='sound_made')
Esempio n. 5
0
    def on_status(self, status):
        """
        This function is a callback by Twitter.

        """
        # Check empty status
        if status is None: return

        # Get extended text if it exists.
        if hasattr(status, 'retweeted_status'):
            try:
                tweet_text = status.retweeted_status.extended_tweet[
                    "full_text"]
            except:
                tweet_text = status.retweeted_status.text
        else:
            try:
                tweet_text = status.extended_tweet["full_text"]
            except AttributeError:
                tweet_text = status.text

        #-----------------------------------------------
        # Get data from the status object. data is a dict.
        data = status._json
        # Add the extended text as a separate key-value pair to
        # data.
        data['tweet_text'] = tweet_text
        try:
            # Put the tweet into the stream called stream_name.
            extend_stream(self.procs, [data], self.stream_name)
            # Increment the number of times data is copied into the stream
            self.n += 1
            # Exit if enough steps have completed.
            # Don't stop if self.num_tweets is None.
            if self.num_tweets and (self.n >= self.num_tweets):
                terminate_stream(self.procs, self.stream_name)
                sys.exit()
            # Yield the thread
            time.sleep(0.0001)
            return True
        except BaseException as e:
            print(' ')
            if not e or str(e) == '':
                print('No data from Twitter')
            else:
                print("Error on_data from Twitter: %s" % str(e))
                print("See TwitterTrackwordsToStream.on_data()")
            print(' ')
            sys.exit()
Esempio n. 6
0
 def source_thread_target(procs):
     extend_stream(procs,
                   data=original_sound_list,
                   stream_name='original_sound')
     terminate_stream(procs, stream_name='original_sound')
Esempio n. 7
0
 def source_thread_target(procs):
     extend_stream(procs,
                   data=np.linspace(0.0, np.pi, 10),
                   stream_name='x')
     terminate_stream(procs, stream_name='x')
Esempio n. 8
0
 def source_thread_target(procs):
     extend_stream(procs, data=DATA, stream_name='data')
     terminate_stream(procs, stream_name='data')