~ubuntu-branches/ubuntu/precise/pyzmq/precise

« back to all changes in this revision

Viewing changes to zmq/core/message.pyx

  • Committer: Package Import Robot
  • Author(s): Debian Python Modules Team
  • Date: 2011-09-23 00:16:39 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: package-import@ubuntu.com-20110923001639-girjqodpb7uv17yu
Tags: 2.1.9-1
* New upstream version
  - should build on kFreeBSD without patches (Closes: #637777).
* Build-depend on zeromq 2.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
"""0MQ Message related classes."""
2
2
 
3
3
#
4
 
#    Copyright (c) 2010 Brian E. Granger
 
4
#    Copyright (c) 2010-2011 Brian E. Granger & Min Ragan-Kelley
5
5
#
6
6
#    This file is part of pyzmq.
7
7
#
35
35
cdef extern from "Python.h":
36
36
    ctypedef int Py_ssize_t
37
37
 
38
 
from czmq cimport *
 
38
from libzmq cimport *
39
39
 
40
40
import time
41
41
 
42
 
 
43
 
from threading import Event, _Event
 
42
try:
 
43
    # below 3.3
 
44
    from threading import _Event as Event
 
45
except ImportError:
 
46
    from threading import Event
44
47
 
45
48
from zmq.core.error import ZMQError, NotDone
46
49
from zmq.utils.strtypes import bytes,unicode,basestring
55
58
    if hint != NULL:
56
59
        tracker_event = (<tuple>hint)[1]
57
60
        Py_DECREF(<object>hint)
58
 
        if isinstance(tracker_event, _Event):
 
61
        if isinstance(tracker_event, Event):
59
62
            # don't assert before DECREF:
60
63
            # assert tracker_queue.empty(), "somebody else wrote to my Queue!"
61
64
            tracker_event.set()
105
108
        self.events = set()
106
109
        self.peers = set()
107
110
        for obj in towatch:
108
 
            if isinstance(obj, _Event):
 
111
            if isinstance(obj, Event):
109
112
                self.events.add(obj)
110
113
            elif isinstance(obj, MessageTracker):
111
114
                self.peers.add(obj)
362
365
            return b.decode()
363
366
        else:
364
367
            return b
365
 
    
366
 
    @property
367
 
    def done(self):
368
 
        """Is 0MQ completely done with the message?"""
369
 
        if not self.tracker:
370
 
            raise ValueError("Not a tracked message")
371
 
        return self.tracker.done
372
 
    
373
 
    def wait(self, timeout=-1):
374
 
        """m.wait(timeout=-1)
375
 
 
376
 
        Wait for 0MQ to be done with the message, or until `timeout`.
377
 
        
378
 
        Parameters
379
 
        ----------
380
 
        timeout : float [default: -1, wait forever]
381
 
            Maximum time in (s) to wait before raising NotDone.
382
 
            
383
 
        
384
 
        Returns
385
 
        -------
386
 
        None
387
 
            if done before `timeout`
388
 
        
389
 
        Raises
390
 
        ------
391
 
        NotDone
392
 
            if `timeout` reached before I am done.
393
 
        """
394
 
        if not self.tracker:
395
 
            raise ValueError("Not a tracked message")
396
 
        return self.tracker.wait(timeout=timeout)
397
368
 
398
369
    cdef inline object _getbuffer(self):
399
370
        """Create a Python buffer/view of the message data.