prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Stream object should have .ptr set to 0, not None.
  The event object expects the stream.ptr to be an integer (size_t) here:
  https://github.com/pfnet/chainer/blob/master/cupy/cuda/stream.py#L56
  https://github.com/pfnet/chainer/blob/master/cupy/cuda/runtime.pyx#L309
  
  In trunk at the moment, recording events with default stream fails via:
  Traceback (most recent call last):
    File "train_imagenet.py", line 85, in <module>
      train_loop()
    File "train_imagenet.py", line 67, in train_loop
      start.record()
    File "/home/awesomebox/anaconda/lib/python2.7/site-packages/chainer-1.5.1-py2.7-linux-x86_64.egg/cupy/cuda/stream.py", line 56, in record
      runtime.eventRecord(self.ptr, stream.ptr)
    File "cupy/cuda/runtime.pyx", line 309, in cupy.cuda.runtime.eventRecord (cupy/cuda/runtime.cpp:6139)
  TypeError: an integer is required
  
  The fix seems simple:
  
  https://github.com/pfnet/chainer/blob/master/cupy/cuda/stream.py#L103
  self.ptr = 0
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `cupy/cuda/stream.py`
  Content:
  ```
  1 from cupy.cuda import runtime
  2 
  3 
  4 class Event(object):
  5 
  6     """CUDA event, a synchronization point of CUDA streams.
  7 
  8     This class handles the CUDA event handle in RAII way, i.e., when an Event
  9     instance is destroyed by the GC, its handle is also destroyed.
  10 
  11     Args:
  12         block (bool): If True, the event blocks on the
  13             :meth:`~cupy.cuda.Event.synchronize` method.
  14         disable_timing (bool): If True, the event does not prepare the timing
  15             data.
  16         interprocess (bool): If True, the event can be passed to other
  17             processes.
  18 
  19     Attributes:
  20         ptr (cupy.cuda.runtime.Stream): Raw stream handle. It can be passed to
  21             the CUDA Runtime API via ctypes.
  22 
  23     """
  24     def __init__(self, block=False, disable_timing=False, interprocess=False):
  25         self.ptr = None
  26 
  27         if interprocess and not disable_timing:
  28             raise ValueError('Timing must be disabled for interprocess events')
  29         flag = ((block and runtime.eventBlockingSync) |
  30                 (disable_timing and runtime.eventDisableTiming) |
  31                 (interprocess and runtime.eventInterprocess))
  32         self.ptr = runtime.eventCreateWithFlags(flag)
  33 
  34     def __del__(self):
  35         if self.ptr:
  36             runtime.eventDestroy(self.ptr)
  37             self.ptr = None
  38 
  39     @property
  40     def done(self):
  41         """True if the event is done."""
  42         return bool(runtime.eventQuery(self.ptr))
  43 
  44     def record(self, stream=None):
  45         """Records the event to a stream.
  46 
  47         Args:
  48             stream (cupy.cuda.Stream): CUDA stream to record event. The null
  49                 stream is used by default.
  50 
  51         .. seealso:: :meth:`cupy.cuda.Stream.record`
  52 
  53         """
  54         if stream is None:
  55             stream = Stream(null=True)
  56         runtime.eventRecord(self.ptr, stream.ptr)
  57 
  58     def synchronize(self):
  59         """Synchronizes all device work to the event.
  60 
  61         If the event is created as a blocking event, it also blocks the CPU
  62         thread until the event is done.
  63 
  64         """
  65         runtime.eventSynchronize(self.ptr)
  66 
  67 
  68 def get_elapsed_time(start_event, end_event):
  69     """Gets the elapsed time between two events.
  70 
  71     Args:
  72         start_event (Event): Earlier event.
  73         end_event (Event): Later event.
  74 
  75     Returns:
  76         float: Elapsed time in milliseconds.
  77 
  78     """
  79     return runtime.eventElapsedTime(start_event.ptr, end_event.ptr)
  80 
  81 
  82 class Stream(object):
  83 
  84     """CUDA stream.
  85 
  86     This class handles the CUDA stream handle in RAII way, i.e., when an Stream
  87     instance is destroyed by the GC, its handle is also destroyed.
  88 
  89     Args:
  90         null (bool): If True, the stream is a null stream (i.e. the default
  91             stream that synchronizes with all streams). Otherwise, a plain new
  92             stream is created.
  93         non_blocking (bool): If True, the stream does not synchronize with the
  94             NULL stream.
  95 
  96     Attributes:
  97         ptr (cupy.cuda.runtime.Stream): Raw stream handle. It can be passed to
  98             the CUDA Runtime API via ctypes.
  99 
  100     """
  101     def __init__(self, null=False, non_blocking=False):
  102         if null:
  103             self.ptr = None
  104         elif non_blocking:
  105             self.ptr = runtime.streamCreateWithFlags(runtime.streamNonBlocking)
  106         else:
  107             self.ptr = runtime.streamCreate()
  108 
  109     def __del__(self):
  110         if self.ptr:
  111             runtime.streamDestroy(self.ptr)
  112             self.ptr = None
  113 
  114     @property
  115     def done(self):
  116         """True if all work on this stream has been done."""
  117         return bool(runtime.streamQuery(self.ptr))
  118 
  119     def synchronize(self):
  120         """Waits for the stream completing all queued work."""
  121         runtime.streamSynchronize(self.ptr)
  122 
  123     def add_callback(self, callback, arg):
  124         """Adds a callback that is called when all queued work is done.
  125 
  126         Args:
  127             callback (function): Callback function. It must take three
  128                 arguments (Stream object, int error status, and user data
  129                 object), and returns nothing.
  130             arg (object): Argument to the callback.
  131 
  132         """
  133         runtime.streamAddCallback(self.ptr, callback, arg)
  134 
  135     def record(self, event=None):
  136         """Records an event on the stream.
  137 
  138         Args:
  139             event (None or cupy.cuda.Event): CUDA event. If None, then a new
  140                 plain event is created and used.
  141 
  142         Returns:
  143             cupy.cuda.Event: The recorded event.
  144 
  145         .. seealso:: :meth:`cupy.cuda.Event.record`
  146 
  147         """
  148         if event is None:
  149             event = Event()
  150         runtime.eventRecord(event.ptr, self.ptr)
  151         return event
  152 
  153     def wait_event(self, event):
  154         """Makes the stream wait for an event.
  155 
  156         The future work on this stream will be done after the event.
  157 
  158         Args:
  159             event (cupy.cuda.Event): CUDA event.
  160 
  161         """
  162         runtime.streamWaitEvent(self.ptr, event)
  163
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/cupy/cuda/stream.py b/cupy/cuda/stream.py
  --- a/cupy/cuda/stream.py
  +++ b/cupy/cuda/stream.py
  @@ -22,7 +22,7 @@
   
       """
       def __init__(self, block=False, disable_timing=False, interprocess=False):
  -        self.ptr = None
  +        self.ptr = 0
   
           if interprocess and not disable_timing:
               raise ValueError('Timing must be disabled for interprocess events')
  @@ -34,7 +34,6 @@
       def __del__(self):
           if self.ptr:
               runtime.eventDestroy(self.ptr)
  -            self.ptr = None
   
       @property
       def done(self):
  @@ -100,7 +99,7 @@
       """
       def __init__(self, null=False, non_blocking=False):
           if null:
  -            self.ptr = None
  +            self.ptr = 0
           elif non_blocking:
               self.ptr = runtime.streamCreateWithFlags(runtime.streamNonBlocking)
           else:
  @@ -109,7 +108,6 @@
       def __del__(self):
           if self.ptr:
               runtime.streamDestroy(self.ptr)
  -            self.ptr = None
   
       @property
       def done(self):
  
verification_info: {"golden_diff": "diff --git a/cupy/cuda/stream.py b/cupy/cuda/stream.py\n--- a/cupy/cuda/stream.py\n+++ b/cupy/cuda/stream.py\n@@ -22,7 +22,7 @@\n \n     \"\"\"\n     def __init__(self, block=False, disable_timing=False, interprocess=False):\n-        self.ptr = None\n+        self.ptr = 0\n \n         if interprocess and not disable_timing:\n             raise ValueError('Timing must be disabled for interprocess events')\n@@ -34,7 +34,6 @@\n     def __del__(self):\n         if self.ptr:\n             runtime.eventDestroy(self.ptr)\n-            self.ptr = None\n \n     @property\n     def done(self):\n@@ -100,7 +99,7 @@\n     \"\"\"\n     def __init__(self, null=False, non_blocking=False):\n         if null:\n-            self.ptr = None\n+            self.ptr = 0\n         elif non_blocking:\n             self.ptr = runtime.streamCreateWithFlags(runtime.streamNonBlocking)\n         else:\n@@ -109,7 +108,6 @@\n     def __del__(self):\n         if self.ptr:\n             runtime.streamDestroy(self.ptr)\n-            self.ptr = None\n \n     @property\n     def done(self):\n", "issue": "Stream object should have .ptr set to 0, not None.\nThe event object expects the stream.ptr to be an integer (size_t) here:\nhttps://github.com/pfnet/chainer/blob/master/cupy/cuda/stream.py#L56\nhttps://github.com/pfnet/chainer/blob/master/cupy/cuda/runtime.pyx#L309\n\nIn trunk at the moment, recording events with default stream fails via:\nTraceback (most recent call last):\n  File \"train_imagenet.py\", line 85, in <module>\n    train_loop()\n  File \"train_imagenet.py\", line 67, in train_loop\n    start.record()\n  File \"/home/awesomebox/anaconda/lib/python2.7/site-packages/chainer-1.5.1-py2.7-linux-x86_64.egg/cupy/cuda/stream.py\", line 56, in record\n    runtime.eventRecord(self.ptr, stream.ptr)\n  File \"cupy/cuda/runtime.pyx\", line 309, in cupy.cuda.runtime.eventRecord (cupy/cuda/runtime.cpp:6139)\nTypeError: an integer is required\n\nThe fix seems simple:\n\nhttps://github.com/pfnet/chainer/blob/master/cupy/cuda/stream.py#L103\nself.ptr = 0\n\n", "before_files": [{"content": "from cupy.cuda import runtime\n\n\nclass Event(object):\n\n    \"\"\"CUDA event, a synchronization point of CUDA streams.\n\n    This class handles the CUDA event handle in RAII way, i.e., when an Event\n    instance is destroyed by the GC, its handle is also destroyed.\n\n    Args:\n        block (bool): If True, the event blocks on the\n            :meth:`~cupy.cuda.Event.synchronize` method.\n        disable_timing (bool): If True, the event does not prepare the timing\n            data.\n        interprocess (bool): If True, the event can be passed to other\n            processes.\n\n    Attributes:\n        ptr (cupy.cuda.runtime.Stream): Raw stream handle. It can be passed to\n            the CUDA Runtime API via ctypes.\n\n    \"\"\"\n    def __init__(self, block=False, disable_timing=False, interprocess=False):\n        self.ptr = None\n\n        if interprocess and not disable_timing:\n            raise ValueError('Timing must be disabled for interprocess events')\n        flag = ((block and runtime.eventBlockingSync) |\n                (disable_timing and runtime.eventDisableTiming) |\n                (interprocess and runtime.eventInterprocess))\n        self.ptr = runtime.eventCreateWithFlags(flag)\n\n    def __del__(self):\n        if self.ptr:\n            runtime.eventDestroy(self.ptr)\n            self.ptr = None\n\n    @property\n    def done(self):\n        \"\"\"True if the event is done.\"\"\"\n        return bool(runtime.eventQuery(self.ptr))\n\n    def record(self, stream=None):\n        \"\"\"Records the event to a stream.\n\n        Args:\n            stream (cupy.cuda.Stream): CUDA stream to record event. The null\n                stream is used by default.\n\n        .. seealso:: :meth:`cupy.cuda.Stream.record`\n\n        \"\"\"\n        if stream is None:\n            stream = Stream(null=True)\n        runtime.eventRecord(self.ptr, stream.ptr)\n\n    def synchronize(self):\n        \"\"\"Synchronizes all device work to the event.\n\n        If the event is created as a blocking event, it also blocks the CPU\n        thread until the event is done.\n\n        \"\"\"\n        runtime.eventSynchronize(self.ptr)\n\n\ndef get_elapsed_time(start_event, end_event):\n    \"\"\"Gets the elapsed time between two events.\n\n    Args:\n        start_event (Event): Earlier event.\n        end_event (Event): Later event.\n\n    Returns:\n        float: Elapsed time in milliseconds.\n\n    \"\"\"\n    return runtime.eventElapsedTime(start_event.ptr, end_event.ptr)\n\n\nclass Stream(object):\n\n    \"\"\"CUDA stream.\n\n    This class handles the CUDA stream handle in RAII way, i.e., when an Stream\n    instance is destroyed by the GC, its handle is also destroyed.\n\n    Args:\n        null (bool): If True, the stream is a null stream (i.e. the default\n            stream that synchronizes with all streams). Otherwise, a plain new\n            stream is created.\n        non_blocking (bool): If True, the stream does not synchronize with the\n            NULL stream.\n\n    Attributes:\n        ptr (cupy.cuda.runtime.Stream): Raw stream handle. It can be passed to\n            the CUDA Runtime API via ctypes.\n\n    \"\"\"\n    def __init__(self, null=False, non_blocking=False):\n        if null:\n            self.ptr = None\n        elif non_blocking:\n            self.ptr = runtime.streamCreateWithFlags(runtime.streamNonBlocking)\n        else:\n            self.ptr = runtime.streamCreate()\n\n    def __del__(self):\n        if self.ptr:\n            runtime.streamDestroy(self.ptr)\n            self.ptr = None\n\n    @property\n    def done(self):\n        \"\"\"True if all work on this stream has been done.\"\"\"\n        return bool(runtime.streamQuery(self.ptr))\n\n    def synchronize(self):\n        \"\"\"Waits for the stream completing all queued work.\"\"\"\n        runtime.streamSynchronize(self.ptr)\n\n    def add_callback(self, callback, arg):\n        \"\"\"Adds a callback that is called when all queued work is done.\n\n        Args:\n            callback (function): Callback function. It must take three\n                arguments (Stream object, int error status, and user data\n                object), and returns nothing.\n            arg (object): Argument to the callback.\n\n        \"\"\"\n        runtime.streamAddCallback(self.ptr, callback, arg)\n\n    def record(self, event=None):\n        \"\"\"Records an event on the stream.\n\n        Args:\n            event (None or cupy.cuda.Event): CUDA event. If None, then a new\n                plain event is created and used.\n\n        Returns:\n            cupy.cuda.Event: The recorded event.\n\n        .. seealso:: :meth:`cupy.cuda.Event.record`\n\n        \"\"\"\n        if event is None:\n            event = Event()\n        runtime.eventRecord(event.ptr, self.ptr)\n        return event\n\n    def wait_event(self, event):\n        \"\"\"Makes the stream wait for an event.\n\n        The future work on this stream will be done after the event.\n\n        Args:\n            event (cupy.cuda.Event): CUDA event.\n\n        \"\"\"\n        runtime.streamWaitEvent(self.ptr, event)\n", "path": "cupy/cuda/stream.py"}], "after_files": [{"content": "from cupy.cuda import runtime\n\n\nclass Event(object):\n\n    \"\"\"CUDA event, a synchronization point of CUDA streams.\n\n    This class handles the CUDA event handle in RAII way, i.e., when an Event\n    instance is destroyed by the GC, its handle is also destroyed.\n\n    Args:\n        block (bool): If True, the event blocks on the\n            :meth:`~cupy.cuda.Event.synchronize` method.\n        disable_timing (bool): If True, the event does not prepare the timing\n            data.\n        interprocess (bool): If True, the event can be passed to other\n            processes.\n\n    Attributes:\n        ptr (cupy.cuda.runtime.Stream): Raw stream handle. It can be passed to\n            the CUDA Runtime API via ctypes.\n\n    \"\"\"\n    def __init__(self, block=False, disable_timing=False, interprocess=False):\n        self.ptr = 0\n\n        if interprocess and not disable_timing:\n            raise ValueError('Timing must be disabled for interprocess events')\n        flag = ((block and runtime.eventBlockingSync) |\n                (disable_timing and runtime.eventDisableTiming) |\n                (interprocess and runtime.eventInterprocess))\n        self.ptr = runtime.eventCreateWithFlags(flag)\n\n    def __del__(self):\n        if self.ptr:\n            runtime.eventDestroy(self.ptr)\n\n    @property\n    def done(self):\n        \"\"\"True if the event is done.\"\"\"\n        return bool(runtime.eventQuery(self.ptr))\n\n    def record(self, stream=None):\n        \"\"\"Records the event to a stream.\n\n        Args:\n            stream (cupy.cuda.Stream): CUDA stream to record event. The null\n                stream is used by default.\n\n        .. seealso:: :meth:`cupy.cuda.Stream.record`\n\n        \"\"\"\n        if stream is None:\n            stream = Stream(null=True)\n        runtime.eventRecord(self.ptr, stream.ptr)\n\n    def synchronize(self):\n        \"\"\"Synchronizes all device work to the event.\n\n        If the event is created as a blocking event, it also blocks the CPU\n        thread until the event is done.\n\n        \"\"\"\n        runtime.eventSynchronize(self.ptr)\n\n\ndef get_elapsed_time(start_event, end_event):\n    \"\"\"Gets the elapsed time between two events.\n\n    Args:\n        start_event (Event): Earlier event.\n        end_event (Event): Later event.\n\n    Returns:\n        float: Elapsed time in milliseconds.\n\n    \"\"\"\n    return runtime.eventElapsedTime(start_event.ptr, end_event.ptr)\n\n\nclass Stream(object):\n\n    \"\"\"CUDA stream.\n\n    This class handles the CUDA stream handle in RAII way, i.e., when an Stream\n    instance is destroyed by the GC, its handle is also destroyed.\n\n    Args:\n        null (bool): If True, the stream is a null stream (i.e. the default\n            stream that synchronizes with all streams). Otherwise, a plain new\n            stream is created.\n        non_blocking (bool): If True, the stream does not synchronize with the\n            NULL stream.\n\n    Attributes:\n        ptr (cupy.cuda.runtime.Stream): Raw stream handle. It can be passed to\n            the CUDA Runtime API via ctypes.\n\n    \"\"\"\n    def __init__(self, null=False, non_blocking=False):\n        if null:\n            self.ptr = 0\n        elif non_blocking:\n            self.ptr = runtime.streamCreateWithFlags(runtime.streamNonBlocking)\n        else:\n            self.ptr = runtime.streamCreate()\n\n    def __del__(self):\n        if self.ptr:\n            runtime.streamDestroy(self.ptr)\n\n    @property\n    def done(self):\n        \"\"\"True if all work on this stream has been done.\"\"\"\n        return bool(runtime.streamQuery(self.ptr))\n\n    def synchronize(self):\n        \"\"\"Waits for the stream completing all queued work.\"\"\"\n        runtime.streamSynchronize(self.ptr)\n\n    def add_callback(self, callback, arg):\n        \"\"\"Adds a callback that is called when all queued work is done.\n\n        Args:\n            callback (function): Callback function. It must take three\n                arguments (Stream object, int error status, and user data\n                object), and returns nothing.\n            arg (object): Argument to the callback.\n\n        \"\"\"\n        runtime.streamAddCallback(self.ptr, callback, arg)\n\n    def record(self, event=None):\n        \"\"\"Records an event on the stream.\n\n        Args:\n            event (None or cupy.cuda.Event): CUDA event. If None, then a new\n                plain event is created and used.\n\n        Returns:\n            cupy.cuda.Event: The recorded event.\n\n        .. seealso:: :meth:`cupy.cuda.Event.record`\n\n        \"\"\"\n        if event is None:\n            event = Event()\n        runtime.eventRecord(event.ptr, self.ptr)\n        return event\n\n    def wait_event(self, event):\n        \"\"\"Makes the stream wait for an event.\n\n        The future work on this stream will be done after the event.\n\n        Args:\n            event (cupy.cuda.Event): CUDA event.\n\n        \"\"\"\n        runtime.streamWaitEvent(self.ptr, event)\n", "path": "cupy/cuda/stream.py"}]}