Why python shell is aborted but it is fine in Jupiter notebook?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why python shell is aborted but it is fine in Jupiter notebook?

WingIDE - User mailing list
Here is a small program I am writing by watching some video lectures. But the following program crashes in the Wing Pro python shell.

Program: other_async_david.py

from collections import deque
from concurrent.futures import Future

class Queuey:
    def __init__(self, maxsize):
        self.maxsize = maxsize
        self.items = deque()
        self.getters = deque()
        self.putters = deque()
   
    def get(self):
        return self.items.popleft()
   
    def get_noblock(self):
        if self.items:
            # Wake a putter
            if self.putters:
                self.putters.popleft().set_result(True)
            return self.items.popleft(), None
        else:
            fut = Future()
            self.getters.append(fut)
            return None, fut
   
    def put(self, item):
        if len(self.items) < self.maxsize:
            self.items.append(item)
        else:
            print('No..')
   
    def put_noblock(self, item):
        if len(self.items) < self.maxsize:
            self.items.append(item)
            # Wake a getter
            if self.getters:
                self.getters.popleft().set_result(
                    self.items.popleft()
                )
        else:
            fut = Future()
            self.putters.append(fut)
            return fut
   
    def get_sync(self):
        item, fut = self.get_noblock()
        if fut:
            item = fut.result()
        return item
   
    def put_sync(self, item):
        while True:
            fut = self.put_noblock(item)
            if fut is None:
                return
            fut.result()

#def producer(q, n):
    #for i in range(n):
        #q.put(i)
   
    #q.put(None)

#def consumer(q):
    #while True:
        #item = q.get()
        #if item is None:
            #break
        #print("Got:", item)
       

def producer(q, n):
    for i in range(n):
        q.put_sync(i)
   
    q.put_sync(None)

def consumer(q):
    while True:
        item = q.get_sync()
        if item is None:
            break
        print("Got:", item)


In Wing Pro shell on end of the program it asks me to restart the shell, aborted. But Jupyter notebook ends it without a problem as course lecturer screen.

Below is the code I executed:

from threading import Thread
from other_async_david import Queuey, consumer, producer
q = Queuey(2)

Thread(target=producer, args=(q, 10)).start()
Thread(target=consumer, args=(q,)).start()


https://www.dropbox.com/s/jwj68dcpemld3vy/Screenshot%202019-05-09%20at%204.44.15%20PM.png?dl=0
https://www.dropbox.com/s/m58se7gjqqepvyb/Screenshot%202019-05-09%20at%204.43.32%20PM.png?dl=0

Thanks,

Arup Rakshit
[hidden email]



_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: Why python shell is aborted but it is fine in Jupiter notebook?

WingIDE - User mailing list
This works if you put the test code in a file and debug that file.
We'll look into why it fails when run in the shell.

Cheers,

John

On 5/9/19 7:18 AM, Arup Rakshit via wingide-users wrote:

> Here is a small program I am writing by watching some video lectures. But the following program crashes in the Wing Pro python shell.
>
> Program: other_async_david.py
>
> from collections import deque
> from concurrent.futures import Future
>
> class Queuey:
>      def __init__(self, maxsize):
>          self.maxsize = maxsize
>          self.items = deque()
>          self.getters = deque()
>          self.putters = deque()
>      
>      def get(self):
>          return self.items.popleft()
>      
>      def get_noblock(self):
>          if self.items:
>              # Wake a putter
>              if self.putters:
>                  self.putters.popleft().set_result(True)
>              return self.items.popleft(), None
>          else:
>              fut = Future()
>              self.getters.append(fut)
>              return None, fut
>      
>      def put(self, item):
>          if len(self.items) < self.maxsize:
>              self.items.append(item)
>          else:
>              print('No..')
>      
>      def put_noblock(self, item):
>          if len(self.items) < self.maxsize:
>              self.items.append(item)
>              # Wake a getter
>              if self.getters:
>                  self.getters.popleft().set_result(
>                      self.items.popleft()
>                  )
>          else:
>              fut = Future()
>              self.putters.append(fut)
>              return fut
>      
>      def get_sync(self):
>          item, fut = self.get_noblock()
>          if fut:
>              item = fut.result()
>          return item
>      
>      def put_sync(self, item):
>          while True:
>              fut = self.put_noblock(item)
>              if fut is None:
>                  return
>              fut.result()
>
> #def producer(q, n):
>      #for i in range(n):
>          #q.put(i)
>      
>      #q.put(None)
>
> #def consumer(q):
>      #while True:
>          #item = q.get()
>          #if item is None:
>              #break
>          #print("Got:", item)
>          
>
> def producer(q, n):
>      for i in range(n):
>          q.put_sync(i)
>      
>      q.put_sync(None)
>
> def consumer(q):
>      while True:
>          item = q.get_sync()
>          if item is None:
>              break
>          print("Got:", item)
>
>
> In Wing Pro shell on end of the program it asks me to restart the shell, aborted. But Jupyter notebook ends it without a problem as course lecturer screen.
>
> Below is the code I executed:
>
> from threading import Thread
> from other_async_david import Queuey, consumer, producer
> q = Queuey(2)
>
> Thread(target=producer, args=(q, 10)).start()
> Thread(target=consumer, args=(q,)).start()
>
>
> https://www.dropbox.com/s/jwj68dcpemld3vy/Screenshot%202019-05-09%20at%204.44.15%20PM.png?dl=0
> https://www.dropbox.com/s/m58se7gjqqepvyb/Screenshot%202019-05-09%20at%204.43.32%20PM.png?dl=0
>
> Thanks,
>
> Arup Rakshit
> [hidden email]
>
>
>
> _________________________________________________
> Wing Python IDE users list
> http://wingware.com/lists/wingide
>

_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide